Series.shift(self, periods=1, freq=None, axis=0, fill_value=None)
[source]
Shift index by desired number of periods with an optional time freq
.
When freq
is not passed, shift the index without realigning the data. If freq
is passed (in this case, the index must be date or datetime, or it will raise a NotImplementedError
), the index will be increased using the periods and the freq
.
Parameters: |
|
---|---|
Returns: |
|
See also
Index.shift
DatetimeIndex.shift
PeriodIndex.shift
tshift
>>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45], ... 'Col2': [13, 23, 18, 33, 48], ... 'Col3': [17, 27, 22, 37, 52]})
>>> df.shift(periods=3) Col1 Col2 Col3 0 NaN NaN NaN 1 NaN NaN NaN 2 NaN NaN NaN 3 10.0 13.0 17.0 4 20.0 23.0 27.0
>>> df.shift(periods=1, axis='columns') Col1 Col2 Col3 0 NaN 10.0 13.0 1 NaN 20.0 23.0 2 NaN 15.0 18.0 3 NaN 30.0 33.0 4 NaN 45.0 48.0
>>> df.shift(periods=3, fill_value=0) Col1 Col2 Col3 0 0 0 0 1 0 0 0 2 0 0 0 3 10 13 17 4 20 23 27
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.Series.shift.html