Clean rows with missing fields
Remove incomplete records before analysis or modeling.
Pandas · Function
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.
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.
DataFrame.dropna(*, axis=0, how=<no_default>, thresh=<no_default>, subset=None, inplace=False, ignore_index=False)| Name | Type | Description |
|---|---|---|
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'. |
thresh | int, optional | Minimum number of non-missing values required. |
subset | column label or iterable of labels, optional | Column or index labels on the other axis to inspect. |
inplace | bool | Modify the DataFrame in place instead of returning a new one. Default: False. |
ignore_index | bool | Relabel the resulting axis with a new default index. Default: False. |
A DataFrame with missing entries removed, or None when inplace=True.
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.
Remove incomplete records before analysis or modeling.
Discard columns that contain missing values under a chosen rule.
Keep records meeting a completeness threshold.
Inspect only required fields while deciding which rows to retain.
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.
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.
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.fillnapandas.DataFrame.isnapandas.DataFrame.notnapandas.Series.dropna