Skip to content

Commit 3ef6f46

Browse files
DaanVanHauwermeirenAnkurDedania
authored andcommitted
DOC: add example for DataFrame.resample: keywords on and level (pandas-dev#15627)
1 parent e8369a1 commit 3ef6f46

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/core/generic.py

+24
Original file line numberDiff line numberDiff line change
@@ -4462,6 +4462,30 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
44624462
2000-01-01 00:06:00 26
44634463
Freq: 3T, dtype: int64
44644464
4465+
For DataFrame objects, the keyword ``on`` can be used to specify the
4466+
column instead of the index for resampling.
4467+
4468+
>>> df = pd.DataFrame(data=9*[range(4)], columns=['a', 'b', 'c', 'd'])
4469+
>>> df['time'] = pd.date_range('1/1/2000', periods=9, freq='T')
4470+
>>> df.resample('3T', on='time').sum()
4471+
a b c d
4472+
time
4473+
2000-01-01 00:00:00 0 3 6 9
4474+
2000-01-01 00:03:00 0 3 6 9
4475+
2000-01-01 00:06:00 0 3 6 9
4476+
4477+
For a DataFrame with MultiIndex, the keyword ``level`` can be used to
4478+
specify on level the resampling needs to take place.
4479+
4480+
>>> time = pd.date_range('1/1/2000', periods=5, freq='T')
4481+
>>> df2 = pd.DataFrame(data=10*[range(4)],
4482+
columns=['a', 'b', 'c', 'd'],
4483+
index=pd.MultiIndex.from_product([time, [1, 2]])
4484+
)
4485+
>>> df2.resample('3T', level=0).sum()
4486+
a b c d
4487+
2000-01-01 00:00:00 0 6 12 18
4488+
2000-01-01 00:03:00 0 4 8 12
44654489
"""
44664490
from pandas.tseries.resample import (resample,
44674491
_maybe_process_deprecations)

0 commit comments

Comments
 (0)