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

Pandas · Function

df.dropna

DataFrame.dropna removes rows or columns containing missing values. Configure the axis, removal rule, minimum non-missing count, inspected labels, mutation behavior, and resulting index.

How it works

Call this DataFrame method to remove rows or columns containing missing values. By default it removes rows containing at least one missing value; use axis, how, thresh, subset, inplace, and ignore_index to control the operation.

Syntax

DataFrame.dropna(*, axis=0, how=<no_default>, thresh=<no_default>, subset=None, inplace=False, ignore_index=False)

Parameters

NameTypeDescription
axis{0 or 'index', 1 or 'columns'}Axis to inspect: 0 or 'index' for rows, or 1 or 'columns' for columns. Default: 0.
how{'any', 'all'}Remove an item if any or all considered values are missing. Default: 'any'.
threshint, optionalMinimum number of non-missing values required.
subsetcolumn label or iterable of labels, optionalColumn or index labels on the other axis to inspect.
inplaceboolModify the DataFrame in place instead of returning a new one. Default: False.
ignore_indexboolRelabel the resulting axis with a new default index. Default: False.

Returns

A DataFrame with missing entries removed, or None when inplace=True.

Key points

  • The method filters missing entries from a DataFrame along a chosen axis.
  • With axis=0 or 'index', the operation removes rows that meet the selected missing-value rule.
  • With axis=1 or 'columns', it removes columns that meet the selected rule.
  • how='any' removes an axis item when at least one considered value is missing.
  • how='all' removes an axis item only when all considered values are missing.
  • thresh sets the minimum count of non-missing values an axis item must have to remain.
  • subset supplies labels on the other axis that limit which values participate in the missingness check.
  • ignore_index controls whether the resulting axis keeps its original labels or is relabeled with a default index.

Common mistakes

  • Do not pass thresh together with how; choose either a minimum non-missing count or an any/all rule.
  • Select one axis per call: rows or columns, rather than attempting to drop along both axes at once.
  • When inplace=True, use the original DataFrame and do not expect the method to return the cleaned DataFrame.

Example: Drop rows using selected columns

import pandas as pd

df = pd.DataFrame({
    "name": ["Ada", "Linus", "Grace"],
    "score": [95, None, 88],
    "note": [None, None, "ok"],
})

clean = df.dropna(subset=["score"])
print(clean)

complete = df.dropna(how="all", subset=["score", "note"])
print(complete)

The first call keeps rows with a score; the second removes rows whose selected fields are all missing.

When to use it

Clean rows with missing fields

Remove incomplete records before analysis or modeling.

Prune incomplete columns

Discard columns that contain missing values under a chosen rule.

Enforce minimum data quality

Keep records meeting a completeness threshold.

Apply a column-scoped check

Inspect only required fields while deciding which rows to retain.

Interview questions

QWhat does dropna do by default?

By default, dropna examines rows because axis defaults to 0. With how='any', a row is removed if at least one missing value is present; how='all' removes it only when every examined value is missing.

Follow-up: How would you require a row to retain enough data? Use thresh with the required number of non-missing values, and do not combine it with how.

QHow do axis and subset affect the operation?

axis=0 or 'index' removes rows, while axis=1 or 'columns' removes columns. The selected axis determines whether the missing-value test is applied to row entries or column entries.

Follow-up: How can the test be limited to particular fields when removing rows? Pass those column labels through subset.

QWhen should thresh or ignore_index be used?

thresh specifies the minimum number of non-NA values required. For row removal, subset can restrict which columns are considered; ignore_index=True makes the resulting axis use a new default integer index.

Follow-up: What happens when inplace=True? The DataFrame is modified directly and the return value is None.

  • pandas.DataFrame.fillna
  • pandas.DataFrame.isna
  • pandas.DataFrame.notna
  • pandas.Series.dropna

Source: pandas.DataFrame.dropna. Checked 2026-10-15.