polars.DataFrame.fill_null#

DataFrame.fill_null(value: Any | None = None, strategy: FillNullStrategy | None = None, limit: int | None = None, matches_supertype: bool = True) DF[source]#

Fill null values using the specified value or strategy.

Parameters:
value

Value used to fill null values.

strategy{None, ‘forward’, ‘backward’, ‘min’, ‘max’, ‘mean’, ‘zero’, ‘one’}

Strategy used to fill null values.

limit

Number of consecutive null values to fill when using the ‘forward’ or ‘backward’ strategy.

matches_supertype

Fill all matching supertype of the fill value.

Returns:
DataFrame with None values replaced by the filling strategy.

See also

fill_nan

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2, None, 4],
...         "b": [0.5, 4, None, 13],
...     }
... )
>>> df.fill_null(99)
shape: (4, 2)
┌─────┬──────┐
│ a   ┆ b    │
│ --- ┆ ---  │
│ i64 ┆ f64  │
╞═════╪══════╡
│ 1   ┆ 0.5  │
├╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 2   ┆ 4.0  │
├╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 99  ┆ 99.0 │
├╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 4   ┆ 13.0 │
└─────┴──────┘