polars.Expr.forward_fill#

Expr.forward_fill(limit: int | None = None) Self[source]#

Fill missing values with the latest seen values.

Parameters:
limit

The number of consecutive null values to forward fill.

See also

backward_fill
shift

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2, None],
...         "b": [4, None, 6],
...     }
... )
>>> df.select(pl.all().forward_fill())
shape: (3, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 4   │
│ 2   ┆ 4   │
│ 2   ┆ 6   │
└─────┴─────┘