Skip to content

Commit 822c90c

Browse files
committed
DOC: update pandas.core.groupby.DataFrameGroupBy.resample docstring.
Better summary and parameters description.
1 parent 957d7a1 commit 822c90c

File tree

1 file changed

+59
-15
lines changed

1 file changed

+59
-15
lines changed

pandas/core/groupby.py

+59-15
Original file line numberDiff line numberDiff line change
@@ -1478,37 +1478,46 @@ def resample(self, rule, *args, **kwargs):
14781478
"""
14791479
Provide resampling when using a TimeGrouper.
14801480
1481-
Given a grouper the function resamples it according to a string and an
1482-
optional list and dictionary of parameters. Returns a new grouper with
1483-
our resampler appended.
1481+
Given a grouper the function resamples it according to a string
1482+
"string" -> "frequency".
1483+
1484+
See the :ref:`frequency aliases <timeseries.offset-aliases>`
1485+
documentation for more details.
14841486
14851487
Parameters
14861488
----------
1487-
rule : str
1489+
rule : str or Offset
14881490
The offset string or object representing target grouper conversion.
1489-
*args
1490-
These parameters will be passed to the get_resampler_for_grouping
1491-
function which builds the approriate resampler and checks for
1492-
deprecated parameters.
1493-
**kwargs
1494-
These parameters will be passed to the get_resampler_for_grouping
1495-
function which builds the approriate resampler and checks for
1496-
deprecated parameters.
1491+
*args, **kwargs
1492+
For compatibility with other groupby methods. Example parameters:
1493+
closed : {‘right’, ‘left’}
1494+
Which side of bin interval is closed
1495+
label : {‘right’, ‘left’}
1496+
Which bin edge label to label bucket with
1497+
loffset : timedelta
1498+
Adjust the resampled time labels
14971499
14981500
Returns
14991501
-------
15001502
Grouper
15011503
Return a new grouper with our resampler appended.
15021504
1505+
See Also
1506+
--------
1507+
pandas.Grouper : specify a frequency to resample with when
1508+
grouping by a key.
1509+
DatetimeIndex.resample : Frequency conversion and resampling of
1510+
time series.
1511+
15031512
Examples
15041513
--------
1505-
Start by creating a DataFrame with 9 one minute timestamps.
1514+
Start by creating a length-9 DataFrame with minute frequency.
15061515
15071516
>>> idx = pd.date_range('1/1/2000', periods=9, freq='T')
1508-
>>> df = pd.DataFrame(data=9*[range(4)],
1517+
>>> df = pd.DataFrame(data=9 * [range(4)],
15091518
... index=idx,
15101519
... columns=['a', 'b', 'c', 'd'])
1511-
>>> df.iloc[[6], [0]] = 5 # change a value for grouping
1520+
>>> df.iloc[6, 0] = 5
15121521
>>> df
15131522
a b c d
15141523
2000-01-01 00:00:00 0 1 2 3
@@ -1563,6 +1572,41 @@ def resample(self, rule, *args, **kwargs):
15631572
a
15641573
0 2000-01-31 0 8 16 24
15651574
5 2000-01-31 5 1 2 3
1575+
1576+
Downsample the series into 3 minute bins as above, but close the right
1577+
side of the bin interval.
1578+
1579+
>>> df.groupby('a').resample('3T', closed='right').sum()
1580+
a b c d
1581+
a
1582+
0 1999-12-31 23:57:00 0 1 2 3
1583+
2000-01-01 00:00:00 0 3 6 9
1584+
2000-01-01 00:03:00 0 2 4 6
1585+
2000-01-01 00:06:00 0 2 4 6
1586+
5 2000-01-01 00:03:00 5 1 2 3
1587+
1588+
Downsample the series into 3 minute bins and close the right side of
1589+
the bin interval, but label each bin using the right edge instead of
1590+
the left.
1591+
1592+
>>> df.groupby('a').resample('3T', closed='right', label='right').sum()
1593+
a b c d
1594+
a
1595+
0 2000-01-01 00:00:00 0 1 2 3
1596+
2000-01-01 00:03:00 0 3 6 9
1597+
2000-01-01 00:06:00 0 2 4 6
1598+
2000-01-01 00:09:00 0 2 4 6
1599+
5 2000-01-01 00:06:00 5 1 2 3
1600+
1601+
Add an offset of twenty seconds.
1602+
1603+
>>> df.groupby('a').resample('3T', loffset='20s').sum()
1604+
a b c d
1605+
a
1606+
0 2000-01-01 00:00:20 0 3 6 9
1607+
2000-01-01 00:03:20 0 3 6 9
1608+
2000-01-01 00:06:20 0 2 4 6
1609+
5 2000-01-01 00:06:20 5 1 2 3
15661610
"""
15671611
from pandas.core.resample import get_resampler_for_grouping
15681612
return get_resampler_for_grouping(self, rule, *args, **kwargs)

0 commit comments

Comments
 (0)