Skip to content

Commit deea3c7

Browse files
committed
DOC: update pandas.core.groupby.DataFrameGroupBy.resample docstring.
Better summary and parameters description.
1 parent 59355d6 commit deea3c7

File tree

1 file changed

+60
-15
lines changed

1 file changed

+60
-15
lines changed

pandas/core/groupby/groupby.py

+60-15
Original file line numberDiff line numberDiff line change
@@ -1462,22 +1462,25 @@ def resample(self, rule, *args, **kwargs):
14621462
"""
14631463
Provide resampling when using a TimeGrouper.
14641464
1465-
Given a grouper the function resamples it according to a string and an
1466-
optional list and dictionary of parameters. Returns a new grouper with
1467-
our resampler appended.
1465+
Given a grouper the function resamples it according to a string
1466+
"string" -> "frequency".
1467+
1468+
See the :ref:`frequency aliases <timeseries.offset-aliases>`
1469+
documentation for more details.
14681470
14691471
Parameters
14701472
----------
1471-
rule : str
1473+
rule : str or Offset
14721474
The offset string or object representing target grouper conversion.
1473-
*args
1474-
These parameters will be passed to the get_resampler_for_grouping
1475-
function which builds the approriate resampler and checks for
1476-
deprecated parameters.
1477-
**kwargs
1478-
These parameters will be passed to the get_resampler_for_grouping
1479-
function which builds the approriate resampler and checks for
1480-
deprecated parameters.
1475+
*args, **kwargs
1476+
For compatibility with other groupby methods. See below for some
1477+
example parameters.
1478+
closed : {‘right’, ‘left’}
1479+
Which side of bin interval is closed.
1480+
label : {‘right’, ‘left’}
1481+
Which bin edge label to label bucket with.
1482+
loffset : timedelta
1483+
Adjust the resampled time labels.
14811484
14821485
Returns
14831486
-------
@@ -1486,13 +1489,13 @@ def resample(self, rule, *args, **kwargs):
14861489
14871490
Examples
14881491
--------
1489-
Start by creating a DataFrame with 9 one minute timestamps.
1492+
Start by creating a length-9 DataFrame with minute frequency.
14901493
14911494
>>> idx = pd.date_range('1/1/2000', periods=9, freq='T')
1492-
>>> df = pd.DataFrame(data=9*[range(4)],
1495+
>>> df = pd.DataFrame(data=9 * [range(4)],
14931496
... index=idx,
14941497
... columns=['a', 'b', 'c', 'd'])
1495-
>>> df.iloc[[6], [0]] = 5 # change a value for grouping
1498+
>>> df.iloc[6, 0] = 5
14961499
>>> df
14971500
a b c d
14981501
2000-01-01 00:00:00 0 1 2 3
@@ -1547,6 +1550,48 @@ def resample(self, rule, *args, **kwargs):
15471550
a
15481551
0 2000-01-31 0 8 16 24
15491552
5 2000-01-31 5 1 2 3
1553+
1554+
Downsample the series into 3 minute bins as above, but close the right
1555+
side of the bin interval.
1556+
1557+
>>> df.groupby('a').resample('3T', closed='right').sum()
1558+
a b c d
1559+
a
1560+
0 1999-12-31 23:57:00 0 1 2 3
1561+
2000-01-01 00:00:00 0 3 6 9
1562+
2000-01-01 00:03:00 0 2 4 6
1563+
2000-01-01 00:06:00 0 2 4 6
1564+
5 2000-01-01 00:03:00 5 1 2 3
1565+
1566+
Downsample the series into 3 minute bins and close the right side of
1567+
the bin interval, but label each bin using the right edge instead of
1568+
the left.
1569+
1570+
>>> df.groupby('a').resample('3T', closed='right', label='right').sum()
1571+
a b c d
1572+
a
1573+
0 2000-01-01 00:00:00 0 1 2 3
1574+
2000-01-01 00:03:00 0 3 6 9
1575+
2000-01-01 00:06:00 0 2 4 6
1576+
2000-01-01 00:09:00 0 2 4 6
1577+
5 2000-01-01 00:06:00 5 1 2 3
1578+
1579+
Add an offset of twenty seconds.
1580+
1581+
>>> df.groupby('a').resample('3T', loffset='20s').sum()
1582+
a b c d
1583+
a
1584+
0 2000-01-01 00:00:20 0 3 6 9
1585+
2000-01-01 00:03:20 0 3 6 9
1586+
2000-01-01 00:06:20 0 2 4 6
1587+
5 2000-01-01 00:06:20 5 1 2 3
1588+
1589+
See Also
1590+
--------
1591+
pandas.Grouper : specify a frequency to resample with when
1592+
grouping by a key.
1593+
DatetimeIndex.resample : Frequency conversion and resampling of
1594+
time series.
15501595
"""
15511596
from pandas.core.resample import get_resampler_for_grouping
15521597
return get_resampler_for_grouping(self, rule, *args, **kwargs)

0 commit comments

Comments
 (0)