Python Practice › Pandas Programs › Program 36

Rows with missing age

EasyPandas Programs · 36 of 95

Write a pandas program to select rows where age is missing.

Advertisement
Output
    name  age
1   John  NaN
3  Klaus  NaN

Approach

  1. isna().

Solution

Python
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
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs