polars.Expr.shift#

Expr.shift(periods: int = 1) Expr[source]#

Shift the values by a given period.

Parameters:
periods

Number of places to shift (may be negative).

Examples

>>> df = pl.DataFrame({"foo": [1, 2, 3, 4]})
>>> df.select(pl.col("foo").shift(1))
shape: (4, 1)
┌──────┐
│ foo  │
│ ---  │
│ i64  │
╞══════╡
│ null │
├╌╌╌╌╌╌┤
│ 1    │
├╌╌╌╌╌╌┤
│ 2    │
├╌╌╌╌╌╌┤
│ 3    │
└──────┘