Skip to content

Commit ceff696

Browse files
committed
DOC: Address PR comments (II) revamp example for the on parameter. (pandas-dev#22894)
1 parent ad1cada commit ceff696

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

pandas/core/generic.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -7589,18 +7589,30 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
75897589
2018-12 4.0
75907590
Freq: M, dtype: float64
75917591
7592-
For DataFrame objects, the keyword ``on`` can be used to specify the
7592+
For DataFrame objects, the keyword `on` can be used to specify the
75937593
column instead of the index for resampling.
75947594
7595-
>>> df = pd.DataFrame(data=9 * [range(4)],
7596-
... columns=['a', 'b', 'c', 'd'])
7597-
>>> df['time'] = pd.date_range('1/1/2000', periods=9, freq='T')
7598-
>>> df.resample('3T', on='time').sum()
7599-
a b c d
7600-
time
7601-
2000-01-01 00:00:00 0 3 6 9
7602-
2000-01-01 00:03:00 0 3 6 9
7603-
2000-01-01 00:06:00 0 3 6 9
7595+
>>> d = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19],
7596+
... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]})
7597+
>>> df = pd.DataFrame(d)
7598+
>>> df['week_starting'] = pd.date_range('01/01/2018',
7599+
... periods=8,
7600+
... freq='W')
7601+
>>> df
7602+
price volume week_starting
7603+
0 10 50 2018-01-07
7604+
1 11 60 2018-01-14
7605+
2 9 40 2018-01-21
7606+
3 13 100 2018-01-28
7607+
4 14 50 2018-02-04
7608+
5 18 100 2018-02-11
7609+
6 17 40 2018-02-18
7610+
7 19 50 2018-02-25
7611+
>>> df.resample('M', on='week_starting').mean()
7612+
price volume
7613+
week_starting
7614+
2018-01-31 10.75 62.5
7615+
2018-02-28 17.00 60.0
76047616
76057617
For a DataFrame with MultiIndex, the keyword ``level`` can be used to
76067618
specify on level the resampling needs to take place.

0 commit comments

Comments
 (0)