@@ -1462,37 +1462,47 @@ 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
-------
1484
1487
Grouper
1485
1488
Return a new grouper with our resampler appended.
1486
1489
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
+
1487
1497
Examples
1488
1498
--------
1489
- Start by creating a DataFrame with 9 one minute timestamps .
1499
+ Start by creating a length-9 DataFrame with minute frequency .
1490
1500
1491
1501
>>> 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)],
1493
1503
... index=idx,
1494
1504
... columns=['a', 'b', 'c', 'd'])
1495
- >>> df.iloc[[6], [0]] = 5 # change a value for grouping
1505
+ >>> df.iloc[6, 0] = 5
1496
1506
>>> df
1497
1507
a b c d
1498
1508
2000-01-01 00:00:00 0 1 2 3
@@ -1547,6 +1557,41 @@ def resample(self, rule, *args, **kwargs):
1547
1557
a
1548
1558
0 2000-01-31 0 8 16 24
1549
1559
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
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