Skip to content

Commit 8cd9a89

Browse files
committed
DOC: Address PR comments (III) revamp example for the level parameter and other cosmetical mods. (pandas-dev#22894)
1 parent ceff696 commit 8cd9a89

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

pandas/core/generic.py

+36-20
Original file line numberDiff line numberDiff line change
@@ -7443,6 +7443,10 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
74437443
To learn more about the offset strings, please see `this link
74447444
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
74457445
7446+
See Also
7447+
--------
7448+
groupby : Group by mapping, function, label, or list of labels.
7449+
74467450
Examples
74477451
--------
74487452
@@ -7540,10 +7544,10 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
75407544
2000-01-01 00:06:00 26
75417545
Freq: 3T, dtype: int64
75427546
7543-
For a Series with a PeriodIndex, the keyword `convention` can be
7547+
For a Series with a PeriodIndex, the keyword ``convention`` can be
75447548
used to control whether to use the start or end of `rule`.
75457549
7546-
Resample a year by quarter using 'start' `convention`. Values are
7550+
Resample a year by quarter using 'start' ``convention``. Values are
75477551
assigned to the first quarter of the period.
75487552
75497553
>>> s = pd.Series([1, 2], index=pd.period_range('2012-01-01',
@@ -7564,12 +7568,12 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
75647568
2013Q4 NaN
75657569
Freq: Q-DEC, dtype: float64
75667570
7567-
Resample quarters by month using 'end' `convention`. Values are
7571+
Resample quarters by month using 'end' ``convention``. Values are
75687572
assigned to the last month of the period.
75697573
75707574
>>> q = pd.Series([1, 2, 3, 4], index=pd.period_range('2018-01-01',
7571-
... freq='Q',
7572-
... periods=4))
7575+
... freq='Q',
7576+
... periods=4))
75737577
>>> q
75747578
2018Q1 1
75757579
2018Q2 2
@@ -7589,7 +7593,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
75897593
2018-12 4.0
75907594
Freq: M, dtype: float64
75917595
7592-
For DataFrame objects, the keyword `on` can be used to specify the
7596+
For DataFrame objects, the keyword ``on`` can be used to specify the
75937597
column instead of the index for resampling.
75947598
75957599
>>> d = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19],
@@ -7615,21 +7619,33 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
76157619
2018-02-28 17.00 60.0
76167620
76177621
For a DataFrame with MultiIndex, the keyword ``level`` can be used to
7618-
specify on level the resampling needs to take place.
7619-
7620-
>>> time = pd.date_range('1/1/2000', periods=5, freq='T')
7621-
>>> df2 = pd.DataFrame(data=10 * [range(4)],
7622-
... columns=['a', 'b', 'c', 'd'],
7623-
... index=pd.MultiIndex.from_product([time, [1, 2]])
7624-
... )
7625-
>>> df2.resample('3T', level=0).sum()
7626-
a b c d
7627-
2000-01-01 00:00:00 0 6 12 18
7628-
2000-01-01 00:03:00 0 4 8 12
7622+
specify on which level the resampling needs to take place.
76297623
7630-
See also
7631-
--------
7632-
groupby : Group by mapping, function, label, or list of labels.
7624+
>>> days = pd.date_range('1/1/2000', periods=4, freq='D')
7625+
>>> d2 = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19],
7626+
... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]})
7627+
>>> df2 = pd.DataFrame(
7628+
... d2,
7629+
... index=pd.MultiIndex.from_product(
7630+
... [days, ['morning', 'afternoon']]
7631+
... )
7632+
... )
7633+
>>> df2
7634+
price volume
7635+
2000-01-01 morning 10 50
7636+
afternoon 11 60
7637+
2000-01-02 morning 9 40
7638+
afternoon 13 100
7639+
2000-01-03 morning 14 50
7640+
afternoon 18 100
7641+
2000-01-04 morning 17 40
7642+
afternoon 19 50
7643+
>>> df2.resample('D', level=0).sum()
7644+
price volume
7645+
2000-01-01 21 110
7646+
2000-01-02 22 140
7647+
2000-01-03 32 150
7648+
2000-01-04 36 90
76337649
"""
76347650
from pandas.core.resample import (resample,
76357651
_maybe_process_deprecations)

0 commit comments

Comments
 (0)