polars.Series.shift

Series.shift(periods: int = 1) polars.internals.series.Series

Shift the values by a given period and fill the parts that will be empty due to this operation with Nones.

Parameters
periods

Number of places to shift (may be negative).

Examples

>>> s = pl.Series("a", [1, 2, 3])
>>> s.shift(periods=1)
shape: (3,)
Series: 'a' [i64]
[
        null
        1
        2
]
>>> s.shift(periods=-1)
shape: (3,)
Series: 'a' [i64]
[
        2
        3
        null
]