Skip to content

Commit 88b9dd1

Browse files
author
Yitzhak Andrade
committed
DOC: update the pandas.Series.shift docstring
1 parent 9372661 commit 88b9dd1

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

pandas/core/generic.py

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6815,26 +6815,26 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
68156815
errors=errors)
68166816

68176817
_shared_docs['shift'] = ("""
6818-
Shift index by desired number of periods with an optional time freq.
6818+
Shift index by desired number of periods with an optional time `freq`.
68196819
6820-
When freq is not passed, shift the index without realign the data.
6821-
If freq is passed (in this case, the index must be date or datetime),
6822-
the index will be increased using the periods and the freq.
6820+
When `freq` is not passed, shift the index without realigning the data.
6821+
If `freq` is passed (in this case, the index must be date or datetime),
6822+
the index will be increased using the periods and the `freq`.
68236823
68246824
Parameters
68256825
----------
68266826
periods : int
6827-
Number of periods to move, can be positive or negative.
6827+
Number of periods to shift; can be positive or negative.
68286828
freq : DateOffset, timedelta, or time rule string, optional
68296829
Increment to use from the tseries module or time rule (e.g. 'EOM').
68306830
See Notes.
6831-
axis : int or str
6832-
Shift direction. %(axes_single_arg)s.
6831+
axis : {0 or ‘index’, 1 or ‘columns’, None}, default None
6832+
Shift direction.
68336833
68346834
Notes
68356835
-----
6836-
If freq is specified then the index values are shifted but the data
6837-
is not realigned. That is, use freq if you would like to extend the
6836+
If `freq` is specified then the index values are shifted but the data
6837+
is not realigned. That is, use `freq` if you would like to extend the
68386838
index when shifting and preserve the original data.
68396839
68406840
Returns
@@ -6843,18 +6843,9 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
68436843
68446844
Examples
68456845
--------
6846-
>>> df = pd.DataFrame({'Col1': [10, 20, 30, 20, 15, 30, 45],
6847-
... 'Col2': [13, 23, 33, 23, 18, 33, 48],
6848-
... 'Col3': [17, 27, 37, 27, 22, 37, 52]})
6849-
>>> print(df)
6850-
Col1 Col2 Col3
6851-
0 10 13 17
6852-
1 20 23 27
6853-
2 30 33 37
6854-
3 20 23 27
6855-
4 15 18 22
6856-
5 30 33 37
6857-
6 45 48 52
6846+
>>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45],
6847+
... 'Col2': [13, 23, 18, 33, 48],
6848+
... 'Col3': [17, 27, 22, 37, 52]})
68586849
68596850
>>> df.shift(periods=3)
68606851
Col1 Col2 Col3
@@ -6863,18 +6854,14 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
68636854
2 NaN NaN NaN
68646855
3 10.0 13.0 17.0
68656856
4 20.0 23.0 27.0
6866-
5 30.0 33.0 37.0
6867-
6 20.0 23.0 27.0
68686857
68696858
>>> df.shift(periods=1, axis=1)
68706859
Col1 Col2 Col3
68716860
0 NaN 10.0 13.0
68726861
1 NaN 20.0 23.0
6873-
2 NaN 30.0 33.0
6874-
3 NaN 20.0 23.0
6875-
4 NaN 15.0 18.0
6876-
5 NaN 30.0 33.0
6877-
6 NaN 45.0 48.0
6862+
2 NaN 15.0 18.0
6863+
3 NaN 30.0 33.0
6864+
4 NaN 45.0 48.0
68786865
68796866
>>> import datetime
68806867
>>> names = ['João', 'Maria', 'Emanuel', 'Jussara', 'José']
@@ -6884,7 +6871,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
68846871
... datetime.datetime(2018, 3, 15, 11, 15),
68856872
... datetime.datetime(2018, 3, 20, 11, 15)]
68866873
>>> df = pd.DataFrame(data={'names': names}, index=dates)
6887-
>>> print(df)
6874+
>>> df
68886875
names
68896876
2018-03-01 11:15:00 João
68906877
2018-03-05 11:15:00 Maria
@@ -6910,8 +6897,8 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
69106897
69116898
See Also
69126899
--------
6913-
slice_shift: Equivalent to shift without copying data.
6914-
tshift: Shift the time index, using the index’s frequency if available.
6900+
tshift : Shift the time index, using the index’s frequency if
6901+
available.
69156902
""")
69166903

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

0 commit comments

Comments
 (0)