dropna()
noun
say it: “DROP en-AY” /ˈdrɑp ˌɛnˈeɪ/
A pandas method that removes the rows, or columns, that have missing values.
What does dropna() do in pandas?
dropna() hands back the table without the rows that have missing values. With no options it drops a row with a
gap in any column, which can remove most of a table; subset names the columns that matter, so only rows missing
those are dropped.
import pandas as pd
intake = pd.read_csv("intake.csv", na_values=["unknown", "-"])
with_age = intake.dropna(subset=["age_years"]) # only rows that have an age
print(len(intake), len(with_age)) # 800 683
In a sentence
- “He gave dropna() subset=['age_years'] so only rows without an age were removed.”
- “dropna() with no options left only 469 of the 800 rows.”
Level: Journeyman · More Python terms at this level
Updated