polars.Expr.backward_fill#

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

Fill missing values with the next to be seen values.

Parameters:
limit

The number of consecutive null values to backward fill.

Examples

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