Python Practice › Pandas Programs › Program 36
Rows with missing age
Write a pandas program to select rows where age is missing.
Output
name age 1 John NaN 3 Klaus NaN
Approach
isna().
Solution
import numpy as npimport pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter", "Klaus"], "age": [30, np.nan, 29, np.nan]})print(df[df["age"].isna()])Output
name age 1 John NaN 3 Klaus NaN
Learn the concept
New to this topic? Read the lesson, then come back.