polars.Expr.is_nan

Expr.is_nan() polars.internals.expr.Expr

Create a boolean expression returning True where the expression values are NaN (Not A Number).

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2, None, 1, 5],
...         "b": [1.0, 2.0, float("nan"), 1.0, 5.0],
...     }
... )
>>> df.with_column(pl.all().is_nan().suffix("_isnan"))  # nan != null
shape: (5, 4)
┌──────┬─────┬─────────┬─────────┐
│ a    ┆ b   ┆ a_isnan ┆ b_isnan │
│ ---  ┆ --- ┆ ---     ┆ ---     │
│ i64  ┆ f64 ┆ bool    ┆ bool    │
╞══════╪═════╪═════════╪═════════╡
│ 1    ┆ 1.0 ┆ false   ┆ false   │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 2    ┆ 2.0 ┆ false   ┆ false   │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ null ┆ NaN ┆ false   ┆ true    │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 1    ┆ 1.0 ┆ false   ┆ false   │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 5    ┆ 5.0 ┆ false   ┆ false   │
└──────┴─────┴─────────┴─────────┘