diff --git a/doc/source/timeseries.rst b/doc/source/timeseries.rst index 36ffe8806f373..fbb2947d8c957 100644 --- a/doc/source/timeseries.rst +++ b/doc/source/timeseries.rst @@ -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``. diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6e35e730d676e..a288c264edd81 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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` @@ -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.