@@ -1307,12 +1307,111 @@ def describe(self, **kwargs):
1307
1307
return result .T
1308
1308
return result .unstack ()
1309
1309
1310
- @Substitution (name = 'groupby' )
1311
- @Appender (_doc_template )
1312
1310
def resample (self , rule , * args , ** kwargs ):
1313
1311
"""
1314
- Provide resampling when using a TimeGrouper
1315
- Return a new grouper with our resampler appended
1312
+ Provide resampling when using a TimeGrouper.
1313
+
1314
+ Given a grouper, the function resamples it according to a string
1315
+ "string" -> "frequency".
1316
+
1317
+ See the :ref:`frequency aliases <timeseries.offset-aliases>`
1318
+ documentation for more details.
1319
+
1320
+ Parameters
1321
+ ----------
1322
+ rule : str or DateOffset
1323
+ The offset string or object representing target grouper conversion.
1324
+ *args, **kwargs
1325
+ Possible arguments are `how`, `fill_method`, `limit`, `kind` and
1326
+ `on`, and other arguments of `TimeGrouper`.
1327
+
1328
+ Returns
1329
+ -------
1330
+ Grouper
1331
+ Return a new grouper with our resampler appended.
1332
+
1333
+ See Also
1334
+ --------
1335
+ pandas.Grouper : Specify a frequency to resample with when
1336
+ grouping by a key.
1337
+ DatetimeIndex.resample : Frequency conversion and resampling of
1338
+ time series.
1339
+
1340
+ Examples
1341
+ --------
1342
+ >>> idx = pd.date_range('1/1/2000', periods=4, freq='T')
1343
+ >>> df = pd.DataFrame(data=4 * [range(2)],
1344
+ ... index=idx,
1345
+ ... columns=['a', 'b'])
1346
+ >>> df.iloc[2, 0] = 5
1347
+ >>> df
1348
+ a b
1349
+ 2000-01-01 00:00:00 0 1
1350
+ 2000-01-01 00:01:00 0 1
1351
+ 2000-01-01 00:02:00 5 1
1352
+ 2000-01-01 00:03:00 0 1
1353
+
1354
+ Downsample the DataFrame into 3 minute bins and sum the values of
1355
+ the timestamps falling into a bin.
1356
+
1357
+ >>> df.groupby('a').resample('3T').sum()
1358
+ a b
1359
+ a
1360
+ 0 2000-01-01 00:00:00 0 2
1361
+ 2000-01-01 00:03:00 0 1
1362
+ 5 2000-01-01 00:00:00 5 1
1363
+
1364
+ Upsample the series into 30 second bins.
1365
+
1366
+ >>> df.groupby('a').resample('30S').sum()
1367
+ a b
1368
+ a
1369
+ 0 2000-01-01 00:00:00 0 1
1370
+ 2000-01-01 00:00:30 0 0
1371
+ 2000-01-01 00:01:00 0 1
1372
+ 2000-01-01 00:01:30 0 0
1373
+ 2000-01-01 00:02:00 0 0
1374
+ 2000-01-01 00:02:30 0 0
1375
+ 2000-01-01 00:03:00 0 1
1376
+ 5 2000-01-01 00:02:00 5 1
1377
+
1378
+ Resample by month. Values are assigned to the month of the period.
1379
+
1380
+ >>> df.groupby('a').resample('M').sum()
1381
+ a b
1382
+ a
1383
+ 0 2000-01-31 0 3
1384
+ 5 2000-01-31 5 1
1385
+
1386
+ Downsample the series into 3 minute bins as above, but close the right
1387
+ side of the bin interval.
1388
+
1389
+ >>> df.groupby('a').resample('3T', closed='right').sum()
1390
+ a b
1391
+ a
1392
+ 0 1999-12-31 23:57:00 0 1
1393
+ 2000-01-01 00:00:00 0 2
1394
+ 5 2000-01-01 00:00:00 5 1
1395
+
1396
+ Downsample the series into 3 minute bins and close the right side of
1397
+ the bin interval, but label each bin using the right edge instead of
1398
+ the left.
1399
+
1400
+ >>> df.groupby('a').resample('3T', closed='right', label='right').sum()
1401
+ a b
1402
+ a
1403
+ 0 2000-01-01 00:00:00 0 1
1404
+ 2000-01-01 00:03:00 0 2
1405
+ 5 2000-01-01 00:03:00 5 1
1406
+
1407
+ Add an offset of twenty seconds.
1408
+
1409
+ >>> df.groupby('a').resample('3T', loffset='20s').sum()
1410
+ a b
1411
+ a
1412
+ 0 2000-01-01 00:00:20 0 2
1413
+ 2000-01-01 00:03:20 0 1
1414
+ 5 2000-01-01 00:00:20 5 1
1316
1415
"""
1317
1416
from pandas .core .resample import get_resampler_for_grouping
1318
1417
return get_resampler_for_grouping (self , rule , * args , ** kwargs )
0 commit comments