@@ -1462,22 +1462,25 @@ def resample(self, rule, *args, **kwargs):
1462
1462
"""
1463
1463
Provide resampling when using a TimeGrouper.
1464
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.
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.
1468
1470
1469
1471
Parameters
1470
1472
----------
1471
- rule : str
1473
+ rule : str or Offset
1472
1474
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.
1481
1484
1482
1485
Returns
1483
1486
-------
@@ -1486,13 +1489,13 @@ def resample(self, rule, *args, **kwargs):
1486
1489
1487
1490
Examples
1488
1491
--------
1489
- Start by creating a DataFrame with 9 one minute timestamps .
1492
+ Start by creating a length-9 DataFrame with minute frequency .
1490
1493
1491
1494
>>> 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)],
1493
1496
... index=idx,
1494
1497
... columns=['a', 'b', 'c', 'd'])
1495
- >>> df.iloc[[6], [0]] = 5 # change a value for grouping
1498
+ >>> df.iloc[6, 0] = 5
1496
1499
>>> df
1497
1500
a b c d
1498
1501
2000-01-01 00:00:00 0 1 2 3
@@ -1547,6 +1550,48 @@ def resample(self, rule, *args, **kwargs):
1547
1550
a
1548
1551
0 2000-01-31 0 8 16 24
1549
1552
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.
1550
1595
"""
1551
1596
from pandas .core .resample import get_resampler_for_grouping
1552
1597
return get_resampler_for_grouping (self , rule , * args , ** kwargs )
0 commit comments