Skip to content

Commit

Permalink
DOC: update pandas.core.groupby.DataFrameGroupBy.resample docstring.
Browse files Browse the repository at this point in the history
Better summary and parameters description.
  • Loading branch information
pandres committed Apr 3, 2018
1 parent 957d7a1 commit 822c90c
Showing 1 changed file with 59 additions and 15 deletions.
74 changes: 59 additions & 15 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,37 +1478,46 @@ def resample(self, rule, *args, **kwargs):
"""
Provide resampling when using a TimeGrouper.
Given a grouper the function resamples it according to a string and an
optional list and dictionary of parameters. Returns a new grouper with
our resampler appended.
Given a grouper the function resamples it according to a string
"string" -> "frequency".
See the :ref:`frequency aliases <timeseries.offset-aliases>`
documentation for more details.
Parameters
----------
rule : str
rule : str or Offset
The offset string or object representing target grouper conversion.
*args
These parameters will be passed to the get_resampler_for_grouping
function which builds the approriate resampler and checks for
deprecated parameters.
**kwargs
These parameters will be passed to the get_resampler_for_grouping
function which builds the approriate resampler and checks for
deprecated parameters.
*args, **kwargs
For compatibility with other groupby methods. Example parameters:
closed : {‘right’, ‘left’}
Which side of bin interval is closed
label : {‘right’, ‘left’}
Which bin edge label to label bucket with
loffset : timedelta
Adjust the resampled time labels
Returns
-------
Grouper
Return a new grouper with our resampler appended.
See Also
--------
pandas.Grouper : specify a frequency to resample with when
grouping by a key.
DatetimeIndex.resample : Frequency conversion and resampling of
time series.
Examples
--------
Start by creating a DataFrame with 9 one minute timestamps.
Start by creating a length-9 DataFrame with minute frequency.
>>> idx = pd.date_range('1/1/2000', periods=9, freq='T')
>>> df = pd.DataFrame(data=9*[range(4)],
>>> df = pd.DataFrame(data=9 * [range(4)],
... index=idx,
... columns=['a', 'b', 'c', 'd'])
>>> df.iloc[[6], [0]] = 5 # change a value for grouping
>>> df.iloc[6, 0] = 5
>>> df
a b c d
2000-01-01 00:00:00 0 1 2 3
Expand Down Expand Up @@ -1563,6 +1572,41 @@ def resample(self, rule, *args, **kwargs):
a
0 2000-01-31 0 8 16 24
5 2000-01-31 5 1 2 3
Downsample the series into 3 minute bins as above, but close the right
side of the bin interval.
>>> df.groupby('a').resample('3T', closed='right').sum()
a b c d
a
0 1999-12-31 23:57:00 0 1 2 3
2000-01-01 00:00:00 0 3 6 9
2000-01-01 00:03:00 0 2 4 6
2000-01-01 00:06:00 0 2 4 6
5 2000-01-01 00:03:00 5 1 2 3
Downsample the series into 3 minute bins and close the right side of
the bin interval, but label each bin using the right edge instead of
the left.
>>> df.groupby('a').resample('3T', closed='right', label='right').sum()
a b c d
a
0 2000-01-01 00:00:00 0 1 2 3
2000-01-01 00:03:00 0 3 6 9
2000-01-01 00:06:00 0 2 4 6
2000-01-01 00:09:00 0 2 4 6
5 2000-01-01 00:06:00 5 1 2 3
Add an offset of twenty seconds.
>>> df.groupby('a').resample('3T', loffset='20s').sum()
a b c d
a
0 2000-01-01 00:00:20 0 3 6 9
2000-01-01 00:03:20 0 3 6 9
2000-01-01 00:06:20 0 2 4 6
5 2000-01-01 00:06:20 5 1 2 3
"""
from pandas.core.resample import get_resampler_for_grouping
return get_resampler_for_grouping(self, rule, *args, **kwargs)
Expand Down

0 comments on commit 822c90c

Please sign in to comment.