modin.pandas.DataFrame.shift¶
- DataFrame.shift(periods: int = 1, freq=None, axis: Union[int, Literal['index', 'columns', 'rows']] = 0, fill_value: Hashable = _NoDefault.no_default) DataFrame [source]¶
Shift data by desired number of periods along axis and replace columns with fill_value (default: None).
Snowpark pandas does not support freq currently.
- Parameters:
periods (int) – Number of periods to shift. Can be positive or negative.
freq (not supported, default None) –
axis ({0 or 'index', 1 or 'columns', None}, default None) – Shift direction.
fill_value (object, optional) – The scalar value to use for newly introduced missing values. the default depends on the dtype of self. For numeric data,
np.nan
is used. For datetime, timedelta, or period data, etc.NaT
is used. For extension dtypes,self.dtype.na_value
is used.
- Returns:
Copy of input object, shifted.
- Return type:
Examples
>>> df = pd.DataFrame({"Col1": [10, 20, 15, 30, 45], ... "Col2": [13, 23, 18, 33, 48], ... "Col3": [17, 27, 22, 37, 52]}, ... index=pd.date_range("2020-01-01", "2020-01-05")) >>> df Col1 Col2 Col3 2020-01-01 10 13 17 2020-01-02 20 23 27 2020-01-03 15 18 22 2020-01-04 30 33 37 2020-01-05 45 48 52
>>> df.shift(periods=3) Col1 Col2 Col3 2020-01-01 NaN NaN NaN 2020-01-02 NaN NaN NaN 2020-01-03 NaN NaN NaN 2020-01-04 10.0 13.0 17.0 2020-01-05 20.0 23.0 27.0
>>> df.shift(periods=1, axis="columns") Col1 Col2 Col3 2020-01-01 None 10 13 2020-01-02 None 20 23 2020-01-03 None 15 18 2020-01-04 None 30 33 2020-01-05 None 45 48
>>> df.shift(periods=3, fill_value=0) Col1 Col2 Col3 2020-01-01 0 0 0 2020-01-02 0 0 0 2020-01-03 0 0 0 2020-01-04 10 13 17 2020-01-05 20 23 27