polars.DataFrame.fill_nan#

DataFrame.fill_nan(fill_value: Expr | int | float | None) DataFrame[source]#

Fill floating point NaN values by an Expression evaluation.

Parameters:
fill_value

Value to fill NaN with.

Returns:
DataFrame with NaN replaced with fill_value

Warning

Note that floating point NaNs (Not a Number) are not missing values! To replace missing values, use fill_null().

See also

fill_null

Examples

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