Skip to content

Commit aacbf85

Browse files
author
Yitzhak Andrade
committed
DOC: update the pandas.Series.shift docstring
1 parent 3348d48 commit aacbf85

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

pandas/core/generic.py

+40-37
Original file line numberDiff line numberDiff line change
@@ -7606,28 +7606,31 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
76067606
Shift index by desired number of periods with an optional time `freq`.
76077607
76087608
When `freq` is not passed, shift the index without realigning the data.
7609-
If `freq` is passed (in this case, the index must be date or datetime),
7610-
the index will be increased using the periods and the `freq`.
7609+
If `freq` is passed (in this case, the index must be date or datetime,
7610+
or it will raises a `NotImplementedError`), the index will be
7611+
increased using the periods and the `freq`.
76117612
76127613
Parameters
76137614
----------
76147615
periods : int
76157616
Number of periods to shift; can be positive or negative.
76167617
freq : DateOffset, timedelta, or time rule string, optional
76177618
Increment to use from the tseries module or time rule (e.g. 'EOM').
7618-
See Notes.
7619+
If `freq` is specified then the index values are shifted but the
7620+
data is not realigned. That is, use `freq` if you would like to
7621+
extend the index when shifting and preserve the original data.
76197622
axis : {0 or ‘index’, 1 or ‘columns’, None}, default None
76207623
Shift direction.
76217624
7622-
Notes
7623-
-----
7624-
If `freq` is specified then the index values are shifted but the data
7625-
is not realigned. That is, use `freq` if you would like to extend the
7626-
index when shifting and preserve the original data.
7627-
76287625
Returns
76297626
-------
7630-
shifted : %(klass)s
7627+
%(klass)s
7628+
Copy of input object, shifted.
7629+
7630+
See Also
7631+
--------
7632+
tshift : Shift the time index, using the index’s frequency if
7633+
available.
76317634
76327635
Examples
76337636
--------
@@ -7651,42 +7654,42 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
76517654
3 NaN 30.0 33.0
76527655
4 NaN 45.0 48.0
76537656
7654-
>>> import datetime
7655-
>>> names = ['João', 'Maria', 'Emanuel', 'Jussara', 'José']
7656-
>>> dates = [datetime.datetime(2018, 3, 1, 11, 15),
7657-
... datetime.datetime(2018, 3, 5, 11, 15),
7658-
... datetime.datetime(2018, 3, 10, 11, 15),
7659-
... datetime.datetime(2018, 3, 15, 11, 15),
7660-
... datetime.datetime(2018, 3, 20, 11, 15)]
7657+
**freq parameter**
7658+
7659+
When using the freq parameter with a :class:pandas.DateTimeIndex
7660+
the index values are shifted but the data is not realigned.
7661+
7662+
>>> names = ['Joaquim', 'Maria', 'Emanuel', 'Jussara', 'Geraldo']
7663+
>>> dates = pd.date_range(start='2018-03-05 11:15:00',
7664+
... freq='5D', periods=5)
76617665
>>> df = pd.DataFrame(data={'names': names}, index=dates)
76627666
>>> df
76637667
names
7664-
2018-03-01 11:15:00 João
7665-
2018-03-05 11:15:00 Maria
7666-
2018-03-10 11:15:00 Emanuel
7667-
2018-03-15 11:15:00 Jussara
7668-
2018-03-20 11:15:00 José
7668+
2018-03-05 11:15:00 Joaquim
7669+
2018-03-10 11:15:00 Maria
7670+
2018-03-15 11:15:00 Emanuel
7671+
2018-03-20 11:15:00 Jussara
7672+
2018-03-25 11:15:00 Geraldo
7673+
7674+
Shift the index by 2 days (offset-alias 'D').
76697675
76707676
>>> df.shift(periods=2, freq='D')
76717677
names
7672-
2018-03-03 11:15:00 João
7673-
2018-03-07 11:15:00 Maria
7674-
2018-03-12 11:15:00 Emanuel
7675-
2018-03-17 11:15:00 Jussara
7676-
2018-03-22 11:15:00 José
7678+
2018-03-07 11:15:00 Joaquim
7679+
2018-03-12 11:15:00 Maria
7680+
2018-03-17 11:15:00 Emanuel
7681+
2018-03-22 11:15:00 Jussara
7682+
2018-03-27 11:15:00 Geraldo
7683+
7684+
Shift the index by 75 minutes (offset-alias 'min').
76777685
76787686
>>> df.shift(periods=75, freq='min')
76797687
names
7680-
2018-03-01 12:30:00 João
7681-
2018-03-05 12:30:00 Maria
7682-
2018-03-10 12:30:00 Emanuel
7683-
2018-03-15 12:30:00 Jussara
7684-
2018-03-20 12:30:00 José
7685-
7686-
See Also
7687-
--------
7688-
tshift : Shift the time index, using the index’s frequency if
7689-
available.
7688+
2018-03-05 12:30:00 Joaquim
7689+
2018-03-10 12:30:00 Maria
7690+
2018-03-15 12:30:00 Emanuel
7691+
2018-03-20 12:30:00 Jussara
7692+
2018-03-25 12:30:00 Geraldo
76907693
""")
76917694

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

0 commit comments

Comments
 (0)