polars.LazyFrame.shift_and_fill#
- LazyFrame.shift_and_fill( ) 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
>>> lf = pl.LazyFrame( ... { ... "a": [1, 3, 5], ... "b": [2, 4, 6], ... } ... ) >>> lf.shift_and_fill(fill_value=0, periods=1).collect() shape: (3, 2) ┌─────┬─────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ i64 │ ╞═════╪═════╡ │ 0 ┆ 0 │ │ 1 ┆ 2 │ │ 3 ┆ 4 │ └─────┴─────┘ >>> lf.shift_and_fill(periods=-1, fill_value=0).collect() shape: (3, 2) ┌─────┬─────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ i64 │ ╞═════╪═════╡ │ 3 ┆ 4 │ │ 5 ┆ 6 │ │ 0 ┆ 0 │ └─────┴─────┘