Skip to content

Commit 957d7a1

Browse files
committed
DOC: update pandas.core.groupby.DataFrameGroupBy.resample docstring.
1 parent aedbd94 commit 957d7a1

File tree

1 file changed

+87
-2
lines changed

1 file changed

+87
-2
lines changed

pandas/core/groupby.py

+87-2
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,93 @@ def describe(self, **kwargs):
14761476
@Appender(_doc_template)
14771477
def resample(self, rule, *args, **kwargs):
14781478
"""
1479-
Provide resampling when using a TimeGrouper
1480-
Return a new grouper with our resampler appended
1479+
Provide resampling when using a TimeGrouper.
1480+
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.
1484+
1485+
Parameters
1486+
----------
1487+
rule : str
1488+
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.
1497+
1498+
Returns
1499+
-------
1500+
Grouper
1501+
Return a new grouper with our resampler appended.
1502+
1503+
Examples
1504+
--------
1505+
Start by creating a DataFrame with 9 one minute timestamps.
1506+
1507+
>>> idx = pd.date_range('1/1/2000', periods=9, freq='T')
1508+
>>> df = pd.DataFrame(data=9*[range(4)],
1509+
... index=idx,
1510+
... columns=['a', 'b', 'c', 'd'])
1511+
>>> df.iloc[[6], [0]] = 5 # change a value for grouping
1512+
>>> df
1513+
a b c d
1514+
2000-01-01 00:00:00 0 1 2 3
1515+
2000-01-01 00:01:00 0 1 2 3
1516+
2000-01-01 00:02:00 0 1 2 3
1517+
2000-01-01 00:03:00 0 1 2 3
1518+
2000-01-01 00:04:00 0 1 2 3
1519+
2000-01-01 00:05:00 0 1 2 3
1520+
2000-01-01 00:06:00 5 1 2 3
1521+
2000-01-01 00:07:00 0 1 2 3
1522+
2000-01-01 00:08:00 0 1 2 3
1523+
1524+
Downsample the DataFrame into 3 minute bins and sum the values of
1525+
the timestamps falling into a bin.
1526+
1527+
>>> df.groupby('a').resample('3T').sum()
1528+
a b c d
1529+
a
1530+
0 2000-01-01 00:00:00 0 3 6 9
1531+
2000-01-01 00:03:00 0 3 6 9
1532+
2000-01-01 00:06:00 0 2 4 6
1533+
5 2000-01-01 00:06:00 5 1 2 3
1534+
1535+
Upsample the series into 30 second bins.
1536+
1537+
>>> df.groupby('a').resample('30S').sum()
1538+
a b c d
1539+
a
1540+
0 2000-01-01 00:00:00 0 1 2 3
1541+
2000-01-01 00:00:30 0 0 0 0
1542+
2000-01-01 00:01:00 0 1 2 3
1543+
2000-01-01 00:01:30 0 0 0 0
1544+
2000-01-01 00:02:00 0 1 2 3
1545+
2000-01-01 00:02:30 0 0 0 0
1546+
2000-01-01 00:03:00 0 1 2 3
1547+
2000-01-01 00:03:30 0 0 0 0
1548+
2000-01-01 00:04:00 0 1 2 3
1549+
2000-01-01 00:04:30 0 0 0 0
1550+
2000-01-01 00:05:00 0 1 2 3
1551+
2000-01-01 00:05:30 0 0 0 0
1552+
2000-01-01 00:06:00 0 0 0 0
1553+
2000-01-01 00:06:30 0 0 0 0
1554+
2000-01-01 00:07:00 0 1 2 3
1555+
2000-01-01 00:07:30 0 0 0 0
1556+
2000-01-01 00:08:00 0 1 2 3
1557+
5 2000-01-01 00:06:00 5 1 2 3
1558+
1559+
Resample by month. Values are assigned to the month of the period.
1560+
1561+
>>> df.groupby('a').resample('M').sum()
1562+
a b c d
1563+
a
1564+
0 2000-01-31 0 8 16 24
1565+
5 2000-01-31 5 1 2 3
14811566
"""
14821567
from pandas.core.resample import get_resampler_for_grouping
14831568
return get_resampler_for_grouping(self, rule, *args, **kwargs)

0 commit comments

Comments
 (0)