Skip to content

Commit 692b5ee

Browse files
fding253TomAugspurger
authored andcommitted
DOC: document convention argument for resample() (pandas-dev#16965)
* DOC: document convention argument for resample()
1 parent cbd0354 commit 692b5ee

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pandas/core/generic.py

+43
Original file line numberDiff line numberDiff line change
@@ -4826,6 +4826,8 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
48264826
label : {'right', 'left'}
48274827
Which bin edge label to label bucket with
48284828
convention : {'start', 'end', 's', 'e'}
4829+
For PeriodIndex only, controls whether to use the start or end of
4830+
`rule`
48294831
loffset : timedelta
48304832
Adjust the resampled time labels
48314833
base : int, default 0
@@ -4946,6 +4948,47 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
49464948
2000-01-01 00:06:00 26
49474949
Freq: 3T, dtype: int64
49484950
4951+
For a Series with a PeriodIndex, the keyword `convention` can be
4952+
used to control whether to use the start or end of `rule`.
4953+
4954+
>>> s = pd.Series([1, 2], index=pd.period_range('2012-01-01',
4955+
freq='A',
4956+
periods=2))
4957+
>>> s
4958+
2012 1
4959+
2013 2
4960+
Freq: A-DEC, dtype: int64
4961+
4962+
Resample by month using 'start' `convention`. Values are assigned to
4963+
the first month of the period.
4964+
4965+
>>> s.resample('M', convention='start').asfreq().head()
4966+
2012-01 1.0
4967+
2012-02 NaN
4968+
2012-03 NaN
4969+
2012-04 NaN
4970+
2012-05 NaN
4971+
Freq: M, dtype: float64
4972+
4973+
Resample by month using 'end' `convention`. Values are assigned to
4974+
the last month of the period.
4975+
4976+
>>> s.resample('M', convention='end').asfreq()
4977+
2012-12 1.0
4978+
2013-01 NaN
4979+
2013-02 NaN
4980+
2013-03 NaN
4981+
2013-04 NaN
4982+
2013-05 NaN
4983+
2013-06 NaN
4984+
2013-07 NaN
4985+
2013-08 NaN
4986+
2013-09 NaN
4987+
2013-10 NaN
4988+
2013-11 NaN
4989+
2013-12 2.0
4990+
Freq: M, dtype: float64
4991+
49494992
For DataFrame objects, the keyword ``on`` can be used to specify the
49504993
column instead of the index for resampling.
49514994

0 commit comments

Comments
 (0)