Filter missing values
Create boolean masks for filtering rows whose selected fields are null.
Polars · Module
Returns a boolean expression that identifies null values element by element. It can be applied to individual expressions or selected columns in DataFrame transformations.
Call is_null on an expression to produce a boolean expression that is true at positions containing a Polars null and false elsewhere. It operates element by element and can be applied to one column, all selected columns, or expressions inside transformations.
Expr.is_null() → ExprExpr; when evaluated, it produces a boolean Series indicating which values are null.
None in the example becomes a detected Polars null.import polars as pl
df = pl.DataFrame({"a": [1, 2, None], "b": [None, 2.0, float("nan")]})
result = df.with_columns(
pl.all().is_null().name.suffix("_isnull")
)
print(result)Adds a boolean column for each input column, marking only Polars null values.
Create boolean masks for filtering rows whose selected fields are null.
Add null-indicator columns during feature inspection or data-quality checks.
Apply the same null test to every selected column with a selector expression.
Expr.is_null() return?is_null() returns an expression whose evaluated result is a boolean Series indicating which values are null. It can be used in transformations such as with_columns and applied to multiple selected columns.
Follow-up: How would you distinguish null from NaN? is_null() detects null values, while the documented example demonstrates that NaN is reported separately rather than as null; use a NaN-specific check for floating-point NaN.
Expr.is_null()?The method takes no arguments and returns an Expr. When evaluated, each input value produces a boolean result: true for null and false for non-null values.
Follow-up: What happens when it is applied through pl.all()? Polars evaluates the expression for every selected column, producing corresponding boolean columns when used with with_columns.
is_null() be used across a DataFrame?A common pattern is pl.all().is_null().name.suffix("_isnull") inside with_columns. This creates null-indicator columns while retaining the original data.
Follow-up: How can the generated columns be named? Use expression name manipulation such as name.suffix to append a suffix to each selected column name.
polars.Expr.is_not_nullpolars.Expr.has_nullspolars.Expr.name.suffix