Skip to content

Commit eb12cbb

Browse files
rhshadrachJulianWgs
authored andcommitted
DOC: Remove multiple blank lines in ipython directives (pandas-dev#41400)
1 parent 6c8cf20 commit eb12cbb

File tree

10 files changed

+2
-37
lines changed

10 files changed

+2
-37
lines changed

doc/source/user_guide/basics.rst

-2
Original file line numberDiff line numberDiff line change
@@ -1184,11 +1184,9 @@ a single value and returning a single value. For example:
11841184
11851185
df4
11861186
1187-
11881187
def f(x):
11891188
return len(str(x))
11901189
1191-
11921190
df4["one"].map(f)
11931191
df4.applymap(f)
11941192

doc/source/user_guide/cookbook.rst

-13
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,12 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
494494
495495
S = pd.Series([i / 100.0 for i in range(1, 11)])
496496
497-
498497
def cum_ret(x, y):
499498
return x * (1 + y)
500499
501-
502500
def red(x):
503501
return functools.reduce(cum_ret, x, 1.0)
504502
505-
506503
S.expanding().apply(red, raw=True)
507504
508505
@@ -514,12 +511,10 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
514511
df = pd.DataFrame({"A": [1, 1, 2, 2], "B": [1, -1, 1, 2]})
515512
gb = df.groupby("A")
516513
517-
518514
def replace(g):
519515
mask = g < 0
520516
return g.where(mask, g[~mask].mean())
521517
522-
523518
gb.transform(replace)
524519
525520
`Sort groups by aggregated data
@@ -551,13 +546,11 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
551546
rng = pd.date_range(start="2014-10-07", periods=10, freq="2min")
552547
ts = pd.Series(data=list(range(10)), index=rng)
553548
554-
555549
def MyCust(x):
556550
if len(x) > 2:
557551
return x[1] * 1.234
558552
return pd.NaT
559553
560-
561554
mhc = {"Mean": np.mean, "Max": np.max, "Custom": MyCust}
562555
ts.resample("5min").apply(mhc)
563556
ts
@@ -803,11 +796,9 @@ Apply
803796
index=["I", "II", "III"],
804797
)
805798
806-
807799
def SeriesFromSubList(aList):
808800
return pd.Series(aList)
809801
810-
811802
df_orgz = pd.concat(
812803
{ind: row.apply(SeriesFromSubList) for ind, row in df.iterrows()}
813804
)
@@ -827,12 +818,10 @@ Rolling Apply to multiple columns where function calculates a Series before a Sc
827818
)
828819
df
829820
830-
831821
def gm(df, const):
832822
v = ((((df["A"] + df["B"]) + 1).cumprod()) - 1) * const
833823
return v.iloc[-1]
834824
835-
836825
s = pd.Series(
837826
{
838827
df.index[i]: gm(df.iloc[i: min(i + 51, len(df) - 1)], 5)
@@ -859,11 +848,9 @@ Rolling Apply to multiple columns where function returns a Scalar (Volume Weight
859848
)
860849
df
861850
862-
863851
def vwap(bars):
864852
return (bars.Close * bars.Volume).sum() / bars.Volume.sum()
865853
866-
867854
window = 5
868855
s = pd.concat(
869856
[

doc/source/user_guide/groupby.rst

-2
Original file line numberDiff line numberDiff line change
@@ -1617,12 +1617,10 @@ column index name will be used as the name of the inserted column:
16171617
}
16181618
)
16191619
1620-
16211620
def compute_metrics(x):
16221621
result = {"b_sum": x["b"].sum(), "c_mean": x["c"].mean()}
16231622
return pd.Series(result, name="metrics")
16241623
1625-
16261624
result = df.groupby("a").apply(compute_metrics)
16271625
16281626
result

doc/source/user_guide/io.rst

-2
Original file line numberDiff line numberDiff line change
@@ -4648,11 +4648,9 @@ chunks.
46484648
46494649
store.append("dfeq", dfeq, data_columns=["number"])
46504650
4651-
46524651
def chunks(l, n):
46534652
return [l[i: i + n] for i in range(0, len(l), n)]
46544653
4655-
46564654
evens = [2, 4, 6, 8, 10]
46574655
coordinates = store.select_as_coordinates("dfeq", "number=evens")
46584656
for c in chunks(coordinates, 2):

doc/source/user_guide/merging.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1578,4 +1578,5 @@ to ``True``.
15781578
You may also keep all the original values even if they are equal.
15791579

15801580
.. ipython:: python
1581+
15811582
df.compare(df2, keep_shape=True, keep_equal=True)

doc/source/user_guide/reshaping.rst

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Reshaping by pivoting DataFrame objects
1818
1919
import pandas._testing as tm
2020
21-
2221
def unpivot(frame):
2322
N, K = frame.shape
2423
data = {
@@ -29,7 +28,6 @@ Reshaping by pivoting DataFrame objects
2928
columns = ["date", "variable", "value"]
3029
return pd.DataFrame(data, columns=columns)
3130
32-
3331
df = unpivot(tm.makeTimeDataFrame(3))
3432
3533
Data is often stored in so-called "stacked" or "record" format:

doc/source/user_guide/sparse.rst

-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ In the example below, we transform the ``Series`` to a sparse representation of
325325
row_levels=["A", "B"], column_levels=["C", "D"], sort_labels=True
326326
)
327327
328-
329328
A
330329
A.todense()
331330
rows

doc/source/user_guide/text.rst

-5
Original file line numberDiff line numberDiff line change
@@ -297,24 +297,19 @@ positional argument (a regex object) and return a string.
297297
# Reverse every lowercase alphabetic word
298298
pat = r"[a-z]+"
299299
300-
301300
def repl(m):
302301
return m.group(0)[::-1]
303302
304-
305303
pd.Series(["foo 123", "bar baz", np.nan], dtype="string").str.replace(
306304
pat, repl, regex=True
307305
)
308306
309-
310307
# Using regex groups
311308
pat = r"(?P<one>\w+) (?P<two>\w+) (?P<three>\w+)"
312309
313-
314310
def repl(m):
315311
return m.group("two").swapcase()
316312
317-
318313
pd.Series(["Foo Bar Baz", np.nan], dtype="string").str.replace(
319314
pat, repl, regex=True
320315
)

doc/source/user_guide/timeseries.rst

-6
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,6 @@ An example of how holidays and holiday calendars are defined:
14221422
MO,
14231423
)
14241424
1425-
14261425
class ExampleCalendar(AbstractHolidayCalendar):
14271426
rules = [
14281427
USMemorialDay,
@@ -1435,7 +1434,6 @@ An example of how holidays and holiday calendars are defined:
14351434
),
14361435
]
14371436
1438-
14391437
cal = ExampleCalendar()
14401438
cal.holidays(datetime.datetime(2012, 1, 1), datetime.datetime(2012, 12, 31))
14411439
@@ -1707,13 +1705,11 @@ We can instead only resample those groups where we have points as follows:
17071705
from functools import partial
17081706
from pandas.tseries.frequencies import to_offset
17091707
1710-
17111708
def round(t, freq):
17121709
# round a Timestamp to a specified freq
17131710
freq = to_offset(freq)
17141711
return pd.Timestamp((t.value // freq.delta.value) * freq.delta.value)
17151712
1716-
17171713
ts.groupby(partial(round, freq="3T")).sum()
17181714
17191715
.. _timeseries.aggregate:
@@ -2255,11 +2251,9 @@ To convert from an ``int64`` based YYYYMMDD representation.
22552251
s = pd.Series([20121231, 20141130, 99991231])
22562252
s
22572253
2258-
22592254
def conv(x):
22602255
return pd.Period(year=x // 10000, month=x // 100 % 100, day=x % 100, freq="D")
22612256
2262-
22632257
s.apply(conv)
22642258
s.apply(conv)[2]
22652259

doc/source/user_guide/window.rst

+1-4
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ from present information back to past information. This allows the rolling windo
212212
213213
df
214214
215-
216215
.. _window.custom_rolling_window:
217216

218217
Custom window rolling
@@ -294,13 +293,12 @@ conditions. In these cases it can be useful to perform forward-looking rolling w
294293
This :func:`BaseIndexer <pandas.api.indexers.BaseIndexer>` subclass implements a closed fixed-width
295294
forward-looking rolling window, and we can use it as follows:
296295

297-
.. ipython:: ipython
296+
.. ipython:: python
298297
299298
from pandas.api.indexers import FixedForwardWindowIndexer
300299
indexer = FixedForwardWindowIndexer(window_size=2)
301300
df.rolling(indexer, min_periods=1).sum()
302301
303-
304302
.. _window.rolling_apply:
305303

306304
Rolling apply
@@ -319,7 +317,6 @@ the windows are cast as :class:`Series` objects (``raw=False``) or ndarray objec
319317
s = pd.Series(range(10))
320318
s.rolling(window=4).apply(mad, raw=True)
321319
322-
323320
.. _window.numba_engine:
324321

325322
Numba engine

0 commit comments

Comments
 (0)