@@ -1478,37 +1478,46 @@ def resample(self, rule, *args, **kwargs):
1478
1478
"""
1479
1479
Provide resampling when using a TimeGrouper.
1480
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.
1481
+ Given a grouper the function resamples it according to a string
1482
+ "string" -> "frequency".
1483
+
1484
+ See the :ref:`frequency aliases <timeseries.offset-aliases>`
1485
+ documentation for more details.
1484
1486
1485
1487
Parameters
1486
1488
----------
1487
- rule : str
1489
+ rule : str or Offset
1488
1490
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.
1491
+ *args, **kwargs
1492
+ For compatibility with other groupby methods. Example parameters:
1493
+ closed : {‘right’, ‘left’}
1494
+ Which side of bin interval is closed
1495
+ label : {‘right’, ‘left’}
1496
+ Which bin edge label to label bucket with
1497
+ loffset : timedelta
1498
+ Adjust the resampled time labels
1497
1499
1498
1500
Returns
1499
1501
-------
1500
1502
Grouper
1501
1503
Return a new grouper with our resampler appended.
1502
1504
1505
+ See Also
1506
+ --------
1507
+ pandas.Grouper : specify a frequency to resample with when
1508
+ grouping by a key.
1509
+ DatetimeIndex.resample : Frequency conversion and resampling of
1510
+ time series.
1511
+
1503
1512
Examples
1504
1513
--------
1505
- Start by creating a DataFrame with 9 one minute timestamps .
1514
+ Start by creating a length-9 DataFrame with minute frequency .
1506
1515
1507
1516
>>> idx = pd.date_range('1/1/2000', periods=9, freq='T')
1508
- >>> df = pd.DataFrame(data=9* [range(4)],
1517
+ >>> df = pd.DataFrame(data=9 * [range(4)],
1509
1518
... index=idx,
1510
1519
... columns=['a', 'b', 'c', 'd'])
1511
- >>> df.iloc[[6], [0]] = 5 # change a value for grouping
1520
+ >>> df.iloc[6, 0] = 5
1512
1521
>>> df
1513
1522
a b c d
1514
1523
2000-01-01 00:00:00 0 1 2 3
@@ -1563,6 +1572,41 @@ def resample(self, rule, *args, **kwargs):
1563
1572
a
1564
1573
0 2000-01-31 0 8 16 24
1565
1574
5 2000-01-31 5 1 2 3
1575
+
1576
+ Downsample the series into 3 minute bins as above, but close the right
1577
+ side of the bin interval.
1578
+
1579
+ >>> df.groupby('a').resample('3T', closed='right').sum()
1580
+ a b c d
1581
+ a
1582
+ 0 1999-12-31 23:57:00 0 1 2 3
1583
+ 2000-01-01 00:00:00 0 3 6 9
1584
+ 2000-01-01 00:03:00 0 2 4 6
1585
+ 2000-01-01 00:06:00 0 2 4 6
1586
+ 5 2000-01-01 00:03:00 5 1 2 3
1587
+
1588
+ Downsample the series into 3 minute bins and close the right side of
1589
+ the bin interval, but label each bin using the right edge instead of
1590
+ the left.
1591
+
1592
+ >>> df.groupby('a').resample('3T', closed='right', label='right').sum()
1593
+ a b c d
1594
+ a
1595
+ 0 2000-01-01 00:00:00 0 1 2 3
1596
+ 2000-01-01 00:03:00 0 3 6 9
1597
+ 2000-01-01 00:06:00 0 2 4 6
1598
+ 2000-01-01 00:09:00 0 2 4 6
1599
+ 5 2000-01-01 00:06:00 5 1 2 3
1600
+
1601
+ Add an offset of twenty seconds.
1602
+
1603
+ >>> df.groupby('a').resample('3T', loffset='20s').sum()
1604
+ a b c d
1605
+ a
1606
+ 0 2000-01-01 00:00:20 0 3 6 9
1607
+ 2000-01-01 00:03:20 0 3 6 9
1608
+ 2000-01-01 00:06:20 0 2 4 6
1609
+ 5 2000-01-01 00:06:20 5 1 2 3
1566
1610
"""
1567
1611
from pandas .core .resample import get_resampler_for_grouping
1568
1612
return get_resampler_for_grouping (self , rule , * args , ** kwargs )
0 commit comments