Skip to content

DOC: Clarify use of resample bins (#14888) #17940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion doc/source/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1485,12 +1485,31 @@ labels.

.. ipython:: python

ts.resample('5Min').mean() # by default label='right'
ts.resample('5Min').mean() # by default label='left'

ts.resample('5Min', label='left').mean()

ts.resample('5Min', label='left', loffset='1s').mean()

.. note::

The default values for ``label`` and ``closed`` is 'left' for all
frequency offsets except for 'M', 'A', 'Q', 'BM', 'BA', 'BQ', and 'W'
which all have a default of 'right'.

.. ipython:: python

rng2 = pd.date_range('1/1/2012', end='3/31/2012', freq='D')
ts2 = pd.Series(range(len(rng2)), index=rng2)

# default: label='right', closed='right'
ts2.resample('M').max()

# default: label='left', closed='left'
ts2.resample('SM').max()

ts2.resample('SM', label='right', closed='right').max()

The ``axis`` parameter can be set to 0 or 1 and allows you to resample the
specified axis for a ``DataFrame``.

Expand Down
10 changes: 7 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5362,9 +5362,13 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
the offset string or object representing target conversion
axis : int, optional, default 0
closed : {'right', 'left'}
Which side of bin interval is closed
Which side of bin interval is closed. The default is 'left'
for all frequency offsets except for 'M', 'A', 'Q', 'BM',
'BA', 'BQ', and 'W' which all have a default of 'right'.
label : {'right', 'left'}
Which bin edge label to label bucket with
Which bin edge label to label bucket with. The default is 'left'
for all frequency offsets except for 'M', 'A', 'Q', 'BM',
'BA', 'BQ', and 'W' which all have a default of 'right'.
convention : {'start', 'end', 's', 'e'}
For PeriodIndex only, controls whether to use the start or end of
`rule`
Expand Down Expand Up @@ -5424,7 +5428,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
value in the bucket used as the label is not included in the bucket,
which it labels. For example, in the original series the
bucket ``2000-01-01 00:03:00`` contains the value 3, but the summed
value in the resampled bucket with the label``2000-01-01 00:03:00``
value in the resampled bucket with the label ``2000-01-01 00:03:00``
does not include 3 (if it did, the summed value would be 6, not 3).
To include this value close the right side of the bin interval as
illustrated in the example below this one.
Expand Down