Python Practice › Pandas Programs › Program 86
Drop rows with any missing value
Write a pandas program to drop rows where at least one value is missing.
Output
name age 0 Alex 30.0 2 Peter 29.0
Approach
dropna().
Solution
import numpy as npimport pandas as pddf = pd.DataFrame({"name": ["Alex", np.nan, "Peter", "Klaus"], "age": [30, np.nan, 29, np.nan]})print(df.dropna())Output
name age 0 Alex 30.0 2 Peter 29.0
Learn the concept
New to this topic? Read the lesson, then come back.