modin.pandas.DataFrame.shift¶

DataFrame.shift(periods: int | Sequence[int] = 1, freq=None, axis: Axis = 0, fill_value: Hashable = _NoDefault.no_default, suffix: str | None = None) → 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 | Sequence[int]) –

    Number of periods to shift. Can be positive or negative. If an iterable of ints, the data will be shifted once by each int. This is equivalent to shifting by one value at a time and concatenating all resulting frames. The resulting columns will have the shift suffixed to their column names. For multiple periods, axis must not be 1.

    Snowpark pandas does not currently support sequences of int for periods.

  • freq (DateOffset, tseries.offsets, timedelta, or str, optional) –

    Offset to use from the tseries module or time rule (e.g. ‘EOM’).

    Snowpark pandas does not yet support this parameter.

  • 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.

  • suffix (str, optional) –

    If str is specified and periods is an iterable, this is added after the column name and before the shift value for each shifted column name.

    Snowpark pandas does not yet support this parameter.

Returns:

Copy of input object, shifted.

Return type:

DataFrame

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
Copy
>>> 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
Copy
>>> 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
Copy
>>> 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
Copy