polars.Expr.shift_and_fill#
- Expr.shift_and_fill(fill_value: IntoExpr, *, periods: int = 1) Self[source]#
- Shift the values by a given period and fill the resulting null values. - Parameters:
- fill_value
- Fill None values with the result of this expression. 
- periods
- Number of places to shift (may be negative). 
 
 - Examples - >>> df = pl.DataFrame({"foo": [1, 2, 3, 4]}) >>> df.select(pl.col("foo").shift_and_fill("a", periods=1)) shape: (4, 1) ┌─────┐ │ foo │ │ --- │ │ str │ ╞═════╡ │ a │ │ 1 │ │ 2 │ │ 3 │ └─────┘