Skip to content

Commit 59355d6

Browse files
committed
DOC: update pandas.core.groupby.DataFrameGroupBy.resample docstring.
1 parent aa3fefc commit 59355d6

File tree

1 file changed

+87
-2
lines changed

1 file changed

+87
-2
lines changed

pandas/core/groupby/groupby.py

+87-2
Original file line numberDiff line numberDiff line change
@@ -1460,8 +1460,93 @@ def describe(self, **kwargs):
14601460
@Appender(_doc_template)
14611461
def resample(self, rule, *args, **kwargs):
14621462
"""
1463-
Provide resampling when using a TimeGrouper
1464-
Return a new grouper with our resampler appended
1463+
Provide resampling when using a TimeGrouper.
1464+
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.
1468+
1469+
Parameters
1470+
----------
1471+
rule : str
1472+
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.
1481+
1482+
Returns
1483+
-------
1484+
Grouper
1485+
Return a new grouper with our resampler appended.
1486+
1487+
Examples
1488+
--------
1489+
Start by creating a DataFrame with 9 one minute timestamps.
1490+
1491+
>>> idx = pd.date_range('1/1/2000', periods=9, freq='T')
1492+
>>> df = pd.DataFrame(data=9*[range(4)],
1493+
... index=idx,
1494+
... columns=['a', 'b', 'c', 'd'])
1495+
>>> df.iloc[[6], [0]] = 5 # change a value for grouping
1496+
>>> df
1497+
a b c d
1498+
2000-01-01 00:00:00 0 1 2 3
1499+
2000-01-01 00:01:00 0 1 2 3
1500+
2000-01-01 00:02:00 0 1 2 3
1501+
2000-01-01 00:03:00 0 1 2 3
1502+
2000-01-01 00:04:00 0 1 2 3
1503+
2000-01-01 00:05:00 0 1 2 3
1504+
2000-01-01 00:06:00 5 1 2 3
1505+
2000-01-01 00:07:00 0 1 2 3
1506+
2000-01-01 00:08:00 0 1 2 3
1507+
1508+
Downsample the DataFrame into 3 minute bins and sum the values of
1509+
the timestamps falling into a bin.
1510+
1511+
>>> df.groupby('a').resample('3T').sum()
1512+
a b c d
1513+
a
1514+
0 2000-01-01 00:00:00 0 3 6 9
1515+
2000-01-01 00:03:00 0 3 6 9
1516+
2000-01-01 00:06:00 0 2 4 6
1517+
5 2000-01-01 00:06:00 5 1 2 3
1518+
1519+
Upsample the series into 30 second bins.
1520+
1521+
>>> df.groupby('a').resample('30S').sum()
1522+
a b c d
1523+
a
1524+
0 2000-01-01 00:00:00 0 1 2 3
1525+
2000-01-01 00:00:30 0 0 0 0
1526+
2000-01-01 00:01:00 0 1 2 3
1527+
2000-01-01 00:01:30 0 0 0 0
1528+
2000-01-01 00:02:00 0 1 2 3
1529+
2000-01-01 00:02:30 0 0 0 0
1530+
2000-01-01 00:03:00 0 1 2 3
1531+
2000-01-01 00:03:30 0 0 0 0
1532+
2000-01-01 00:04:00 0 1 2 3
1533+
2000-01-01 00:04:30 0 0 0 0
1534+
2000-01-01 00:05:00 0 1 2 3
1535+
2000-01-01 00:05:30 0 0 0 0
1536+
2000-01-01 00:06:00 0 0 0 0
1537+
2000-01-01 00:06:30 0 0 0 0
1538+
2000-01-01 00:07:00 0 1 2 3
1539+
2000-01-01 00:07:30 0 0 0 0
1540+
2000-01-01 00:08:00 0 1 2 3
1541+
5 2000-01-01 00:06:00 5 1 2 3
1542+
1543+
Resample by month. Values are assigned to the month of the period.
1544+
1545+
>>> df.groupby('a').resample('M').sum()
1546+
a b c d
1547+
a
1548+
0 2000-01-31 0 8 16 24
1549+
5 2000-01-31 5 1 2 3
14651550
"""
14661551
from pandas.core.resample import get_resampler_for_grouping
14671552
return get_resampler_for_grouping(self, rule, *args, **kwargs)

0 commit comments

Comments
 (0)