Skip to content

Commit ad1cada

Browse files
committed
DOC: Address PR comments (I) axis type and defaults, improve resample convention examples. (pandas-dev#22894)
1 parent b8f8b0e commit ad1cada

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

pandas/core/generic.py

+38-30
Original file line numberDiff line numberDiff line change
@@ -7383,7 +7383,7 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
73837383
.. deprecated:: 0.18.0
73847384
The new syntax is ``.resample(...).mean()``, or
73857385
``.resample(...).apply(<func>)``
7386-
axis : int, optional, default 0
7386+
axis : {0 or 'index'}, default 0
73877387
Which axis to use for up- or down-sampling. For ``Series`` this
73887388
will default to 0, i.e. `along the rows`. Must be
73897389
``DatetimeIndex``, ``TimedeltaIndex`` or ``PeriodIndex``.
@@ -7543,42 +7543,50 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
75437543
For a Series with a PeriodIndex, the keyword `convention` can be
75447544
used to control whether to use the start or end of `rule`.
75457545
7546+
Resample a year by quarter using 'start' `convention`. Values are
7547+
assigned to the first quarter of the period.
7548+
75467549
>>> s = pd.Series([1, 2], index=pd.period_range('2012-01-01',
75477550
... freq='A',
75487551
... periods=2))
75497552
>>> s
75507553
2012 1
75517554
2013 2
75527555
Freq: A-DEC, dtype: int64
7553-
7554-
Resample by month using 'start' `convention`. Values are assigned to
7555-
the first month of the period.
7556-
7557-
>>> s.resample('M', convention='start').asfreq().head()
7558-
2012-01 1.0
7559-
2012-02 NaN
7560-
2012-03 NaN
7561-
2012-04 NaN
7562-
2012-05 NaN
7563-
Freq: M, dtype: float64
7564-
7565-
Resample by month using 'end' `convention`. Values are assigned to
7566-
the last month of the period.
7567-
7568-
>>> s.resample('M', convention='end').asfreq()
7569-
2012-12 1.0
7570-
2013-01 NaN
7571-
2013-02 NaN
7572-
2013-03 NaN
7573-
2013-04 NaN
7574-
2013-05 NaN
7575-
2013-06 NaN
7576-
2013-07 NaN
7577-
2013-08 NaN
7578-
2013-09 NaN
7579-
2013-10 NaN
7580-
2013-11 NaN
7581-
2013-12 2.0
7556+
>>> s.resample('Q', convention='start').asfreq()
7557+
2012Q1 1.0
7558+
2012Q2 NaN
7559+
2012Q3 NaN
7560+
2012Q4 NaN
7561+
2013Q1 2.0
7562+
2013Q2 NaN
7563+
2013Q3 NaN
7564+
2013Q4 NaN
7565+
Freq: Q-DEC, dtype: float64
7566+
7567+
Resample quarters by month using 'end' `convention`. Values are
7568+
assigned to the last month of the period.
7569+
7570+
>>> q = pd.Series([1, 2, 3, 4], index=pd.period_range('2018-01-01',
7571+
... freq='Q',
7572+
... periods=4))
7573+
>>> q
7574+
2018Q1 1
7575+
2018Q2 2
7576+
2018Q3 3
7577+
2018Q4 4
7578+
Freq: Q-DEC, dtype: int64
7579+
>>> q.resample('M', convention='end').asfreq()
7580+
2018-03 1.0
7581+
2018-04 NaN
7582+
2018-05 NaN
7583+
2018-06 2.0
7584+
2018-07 NaN
7585+
2018-08 NaN
7586+
2018-09 3.0
7587+
2018-10 NaN
7588+
2018-11 NaN
7589+
2018-12 4.0
75827590
Freq: M, dtype: float64
75837591
75847592
For DataFrame objects, the keyword ``on`` can be used to specify the

0 commit comments

Comments
 (0)