From 42b8c8f407d8477518e271efb1a201b39ab02dd1 Mon Sep 17 00:00:00 2001 From: Fiona Ding Date: Sat, 15 Jul 2017 16:50:16 -0500 Subject: [PATCH 1/2] DOC: document convention argument for resample() --- pandas/core/generic.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a4bb746722c1e..5d76d625aec81 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,50 @@ 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``. + + >>> series_p = pd.Series([1, 2], + index=pd.period_range('2012-01-01', + freq='A', + periods=2 + ) + ) + >>> series_p + 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. + + >>> series_p.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. + + >>> series_p.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. From 6653dbe2dbce08d50ef67b132b053389a3977707 Mon Sep 17 00:00:00 2001 From: Fiona Ding Date: Sun, 16 Jul 2017 09:45:43 -0500 Subject: [PATCH 2/2] DOC: document convention argument for resample() --- pandas/core/generic.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5d76d625aec81..e4e2e0093b1a6 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4948,24 +4948,21 @@ 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``. - - >>> series_p = pd.Series([1, 2], - index=pd.period_range('2012-01-01', - freq='A', - periods=2 - ) - ) - >>> series_p + 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 + Resample by month using 'start' `convention`. Values are assigned to the first month of the period. - >>> series_p.resample('M', convention='start').asfreq().head() + >>> s.resample('M', convention='start').asfreq().head() 2012-01 1.0 2012-02 NaN 2012-03 NaN @@ -4973,10 +4970,10 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None, 2012-05 NaN Freq: M, dtype: float64 - Resample by month using 'end' ``convention``. Values are assigned to + Resample by month using 'end' `convention`. Values are assigned to the last month of the period. - >>> series_p.resample('M', convention='end').asfreq() + >>> s.resample('M', convention='end').asfreq() 2012-12 1.0 2013-01 NaN 2013-02 NaN