From 692b5eeeff9b8e8c750f3e64db0c39dc149a73e8 Mon Sep 17 00:00:00 2001 From: fding253 Date: Sun, 16 Jul 2017 10:55:33 -0500 Subject: [PATCH] DOC: document convention argument for resample() (#16965) * DOC: document convention argument for resample() --- pandas/core/generic.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a4bb746722c1e..e4e2e0093b1a6 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4826,6 +4826,8 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None, label : {'right', 'left'} Which bin edge label to label bucket with convention : {'start', 'end', 's', 'e'} + For PeriodIndex only, controls whether to use the start or end of + `rule` loffset : timedelta Adjust the resampled time labels base : int, default 0 @@ -4946,6 +4948,47 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None, 2000-01-01 00:06:00 26 Freq: 3T, dtype: int64 + For a Series with a PeriodIndex, the keyword `convention` can be + used to control whether to use the start or end of `rule`. + + >>> s = pd.Series([1, 2], index=pd.period_range('2012-01-01', + freq='A', + periods=2)) + >>> s + 2012 1 + 2013 2 + Freq: A-DEC, dtype: int64 + + Resample by month using 'start' `convention`. Values are assigned to + the first month of the period. + + >>> s.resample('M', convention='start').asfreq().head() + 2012-01 1.0 + 2012-02 NaN + 2012-03 NaN + 2012-04 NaN + 2012-05 NaN + Freq: M, dtype: float64 + + Resample by month using 'end' `convention`. Values are assigned to + the last month of the period. + + >>> s.resample('M', convention='end').asfreq() + 2012-12 1.0 + 2013-01 NaN + 2013-02 NaN + 2013-03 NaN + 2013-04 NaN + 2013-05 NaN + 2013-06 NaN + 2013-07 NaN + 2013-08 NaN + 2013-09 NaN + 2013-10 NaN + 2013-11 NaN + 2013-12 2.0 + Freq: M, dtype: float64 + For DataFrame objects, the keyword ``on`` can be used to specify the column instead of the index for resampling.