@@ -1462,37 +1462,47 @@ 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 -------
14841487 Grouper
14851488 Return a new grouper with our resampler appended.
14861489
1490+ See Also
1491+ --------
1492+ pandas.Grouper : specify a frequency to resample with when
1493+ grouping by a key.
1494+ DatetimeIndex.resample : Frequency conversion and resampling of
1495+ time series.
1496+
14871497 Examples
14881498 --------
1489- Start by creating a DataFrame with 9 one minute timestamps .
1499+ Start by creating a length-9 DataFrame with minute frequency .
14901500
14911501 >>> idx = pd.date_range('1/1/2000', periods=9, freq='T')
1492- >>> df = pd.DataFrame(data=9* [range(4)],
1502+ >>> df = pd.DataFrame(data=9 * [range(4)],
14931503 ... index=idx,
14941504 ... columns=['a', 'b', 'c', 'd'])
1495- >>> df.iloc[[6], [0]] = 5 # change a value for grouping
1505+ >>> df.iloc[6, 0] = 5
14961506 >>> df
14971507 a b c d
14981508 2000-01-01 00:00:00 0 1 2 3
@@ -1547,6 +1557,41 @@ def resample(self, rule, *args, **kwargs):
15471557 a
15481558 0 2000-01-31 0 8 16 24
15491559 5 2000-01-31 5 1 2 3
1560+
1561+ Downsample the series into 3 minute bins as above, but close the right
1562+ side of the bin interval.
1563+
1564+ >>> df.groupby('a').resample('3T', closed='right').sum()
1565+ a b c d
1566+ a
1567+ 0 1999-12-31 23:57:00 0 1 2 3
1568+ 2000-01-01 00:00:00 0 3 6 9
1569+ 2000-01-01 00:03:00 0 2 4 6
1570+ 2000-01-01 00:06:00 0 2 4 6
1571+ 5 2000-01-01 00:03:00 5 1 2 3
1572+
1573+ Downsample the series into 3 minute bins and close the right side of
1574+ the bin interval, but label each bin using the right edge instead of
1575+ the left.
1576+
1577+ >>> df.groupby('a').resample('3T', closed='right', label='right').sum()
1578+ a b c d
1579+ a
1580+ 0 2000-01-01 00:00:00 0 1 2 3
1581+ 2000-01-01 00:03:00 0 3 6 9
1582+ 2000-01-01 00:06:00 0 2 4 6
1583+ 2000-01-01 00:09:00 0 2 4 6
1584+ 5 2000-01-01 00:06:00 5 1 2 3
1585+
1586+ Add an offset of twenty seconds.
1587+
1588+ >>> df.groupby('a').resample('3T', loffset='20s').sum()
1589+ a b c d
1590+ a
1591+ 0 2000-01-01 00:00:20 0 3 6 9
1592+ 2000-01-01 00:03:20 0 3 6 9
1593+ 2000-01-01 00:06:20 0 2 4 6
1594+ 5 2000-01-01 00:06:20 5 1 2 3
15501595 """
15511596 from pandas .core .resample import get_resampler_for_grouping
15521597 return get_resampler_for_grouping (self , rule , * args , ** kwargs )
0 commit comments