Skip to content

Commit 23fae32

Browse files
ZackStoneJustinZhengBC
authored andcommitted
DOC: update the pandas.Series.shift docstring (pandas-dev#20472)
1 parent b0c4156 commit 23fae32

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

pandas/core/generic.py

+42-15
Original file line numberDiff line numberDiff line change
@@ -8421,32 +8421,59 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
84218421
errors=errors)
84228422

84238423
_shared_docs['shift'] = ("""
8424-
Shift index by desired number of periods with an optional time freq
8424+
Shift index by desired number of periods with an optional time `freq`.
8425+
8426+
When `freq` is not passed, shift the index without realigning the data.
8427+
If `freq` is passed (in this case, the index must be date or datetime,
8428+
or it will raise a `NotImplementedError`), the index will be
8429+
increased using the periods and the `freq`.
84258430
84268431
Parameters
84278432
----------
84288433
periods : int
8429-
Number of periods to move, can be positive or negative.
8430-
freq : DateOffset, timedelta, or time rule string, optional
8431-
Increment to use from the tseries module or time rule (e.g. 'EOM').
8432-
See Notes.
8433-
axis : %(axes_single_arg)s
8434+
Number of periods to shift. Can be positive or negative.
8435+
freq : DateOffset, tseries.offsets, timedelta, or str, optional
8436+
Offset to use from the tseries module or time rule (e.g. 'EOM').
8437+
If `freq` is specified then the index values are shifted but the
8438+
data is not realigned. That is, use `freq` if you would like to
8439+
extend the index when shifting and preserve the original data.
8440+
axis : {0 or 'index', 1 or 'columns', None}, default None
8441+
Shift direction.
8442+
8443+
Returns
8444+
-------
8445+
%(klass)s
8446+
Copy of input object, shifted.
84348447
84358448
See Also
84368449
--------
84378450
Index.shift : Shift values of Index.
84388451
DatetimeIndex.shift : Shift values of DatetimeIndex.
84398452
PeriodIndex.shift : Shift values of PeriodIndex.
8453+
tshift : Shift the time index, using the index's frequency if
8454+
available.
84408455
8441-
Notes
8442-
-----
8443-
If freq is specified then the index values are shifted but the data
8444-
is not realigned. That is, use freq if you would like to extend the
8445-
index when shifting and preserve the original data.
8446-
8447-
Returns
8448-
-------
8449-
shifted : %(klass)s
8456+
Examples
8457+
--------
8458+
>>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45],
8459+
... 'Col2': [13, 23, 18, 33, 48],
8460+
... 'Col3': [17, 27, 22, 37, 52]})
8461+
8462+
>>> df.shift(periods=3)
8463+
Col1 Col2 Col3
8464+
0 NaN NaN NaN
8465+
1 NaN NaN NaN
8466+
2 NaN NaN NaN
8467+
3 10.0 13.0 17.0
8468+
4 20.0 23.0 27.0
8469+
8470+
>>> df.shift(periods=1, axis='columns')
8471+
Col1 Col2 Col3
8472+
0 NaN 10.0 13.0
8473+
1 NaN 20.0 23.0
8474+
2 NaN 15.0 18.0
8475+
3 NaN 30.0 33.0
8476+
4 NaN 45.0 48.0
84508477
""")
84518478

84528479
@Appender(_shared_docs['shift'] % _shared_doc_kwargs)

0 commit comments

Comments
 (0)