Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Module

df.drop_nulls

Removes rows containing nulls from a Polars DataFrame. By default every column is checked, but subset can restrict the check to named columns or a selector.

How it works

drop_nulls returns a new DataFrame after removing rows that have nulls in the selected columns. With no subset, every column participates; with a column name collection or selector, only those columns determine which rows are removed, and the surviving rows keep their original order.

Syntax

DataFrame.drop_nulls(subset: ColumnNameOrSelector | Collection[ColumnNameOrSelector] | None = None) → DataFrame

Parameters

NameTypeDescription
subsetColumnNameOrSelector | Collection[ColumnNameOrSelector] | None = NoneColumn name or names whose null values are considered; when None, all columns are used. A selector is also accepted.

Returns

A new DataFrame with rows containing considered null values removed.

Key points

  • The method removes any row containing at least one null among the columns it considers.
  • Rows that survive filtering remain in their existing relative order.
  • Leaving subset unspecified makes every DataFrame column participate in the null check.
  • Providing subset limits the columns whose nulls can cause row removal.
  • The subset can be expressed with column names or a Polars selector.

Common mistakes

  • This method does not remove NaN values; use drop_nans() when NaN handling is required.

Example: Drop rows using a column selector

import polars as pl
import polars.selectors as cs

df = pl.DataFrame({
    "id": [1, 2, 3],
    "score": [10, None, 30],
    "label": ["a", "b", None],
})

clean = df.drop_nulls(subset=cs.numeric())
print(clean)

Removes rows with nulls in numeric columns while retaining the row whose only null is in the non-numeric label column.

When to use it

Remove incomplete rows

Prepare complete-case data before analysis when any missing field makes a row unusable.

Check selected fields

Validate required fields while allowing optional columns to remain null.

Filter with selectors

Apply the same missingness rule across a type-defined group of columns.

Interview questions

QWhat does DataFrame.drop_nulls() do by default?

It returns a DataFrame containing only rows without nulls in the columns being considered. If subset is omitted, all columns are checked, and the remaining rows preserve their original order.

Follow-up: How would you retain rows with nulls in nonessential columns? Pass only the required column names or a selector through subset, so nulls elsewhere do not trigger removal.

QHow does the subset parameter change behavior?

subset identifies the columns whose null values should cause a row to be dropped. It accepts one column name, a collection of column names, or a selector; None means all columns.

Follow-up: How could you apply the same rule to every integer column without listing them? Use a selector such as polars.selectors.integer() as the subset.

QDoes drop_nulls remove NaN values?

The operation checks for null values, not NaN values. A floating-point NaN therefore requires the separate drop_nans() method if it should be removed.

Follow-up: What should be used when both missing-value representations may occur? Apply the appropriate null and NaN operations explicitly, because the documentation distinguishes the two values.

  • DataFrame.drop_nans
  • polars.selectors.integer

Source: polars.DataFrame.drop_nulls — Polars documentation. Checked 2026-10-15.