Skip to content

Commit 5b99ae2

Browse files
reidy-pjorisvandenbossche
authored andcommitted
DOC: Clarify use of resample bins (#14888) (#17940)
1 parent e2b49ba commit 5b99ae2

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

doc/source/timeseries.rst

+20-1
Original file line numberDiff line numberDiff line change
@@ -1492,12 +1492,31 @@ labels.
14921492

14931493
.. ipython:: python
14941494
1495-
ts.resample('5Min').mean() # by default label='right'
1495+
ts.resample('5Min').mean() # by default label='left'
14961496
14971497
ts.resample('5Min', label='left').mean()
14981498
14991499
ts.resample('5Min', label='left', loffset='1s').mean()
15001500
1501+
.. note::
1502+
1503+
The default values for ``label`` and ``closed`` is 'left' for all
1504+
frequency offsets except for 'M', 'A', 'Q', 'BM', 'BA', 'BQ', and 'W'
1505+
which all have a default of 'right'.
1506+
1507+
.. ipython:: python
1508+
1509+
rng2 = pd.date_range('1/1/2012', end='3/31/2012', freq='D')
1510+
ts2 = pd.Series(range(len(rng2)), index=rng2)
1511+
1512+
# default: label='right', closed='right'
1513+
ts2.resample('M').max()
1514+
1515+
# default: label='left', closed='left'
1516+
ts2.resample('SM').max()
1517+
1518+
ts2.resample('SM', label='right', closed='right').max()
1519+
15011520
The ``axis`` parameter can be set to 0 or 1 and allows you to resample the
15021521
specified axis for a ``DataFrame``.
15031522

pandas/core/generic.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -5362,9 +5362,13 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
53625362
the offset string or object representing target conversion
53635363
axis : int, optional, default 0
53645364
closed : {'right', 'left'}
5365-
Which side of bin interval is closed
5365+
Which side of bin interval is closed. The default is 'left'
5366+
for all frequency offsets except for 'M', 'A', 'Q', 'BM',
5367+
'BA', 'BQ', and 'W' which all have a default of 'right'.
53665368
label : {'right', 'left'}
5367-
Which bin edge label to label bucket with
5369+
Which bin edge label to label bucket with. The default is 'left'
5370+
for all frequency offsets except for 'M', 'A', 'Q', 'BM',
5371+
'BA', 'BQ', and 'W' which all have a default of 'right'.
53685372
convention : {'start', 'end', 's', 'e'}
53695373
For PeriodIndex only, controls whether to use the start or end of
53705374
`rule`
@@ -5424,7 +5428,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
54245428
value in the bucket used as the label is not included in the bucket,
54255429
which it labels. For example, in the original series the
54265430
bucket ``2000-01-01 00:03:00`` contains the value 3, but the summed
5427-
value in the resampled bucket with the label``2000-01-01 00:03:00``
5431+
value in the resampled bucket with the label ``2000-01-01 00:03:00``
54285432
does not include 3 (if it did, the summed value would be 6, not 3).
54295433
To include this value close the right side of the bin interval as
54305434
illustrated in the example below this one.

0 commit comments

Comments
 (0)