Python Practice › Pandas Programs › Program 88

Drop rows that are entirely missing

EasyPandas Programs · 88 of 95

Write a pandas program to drop rows where all values are missing.

Advertisement
Output
    name   age
0   Alex  30.0
2  Peter   NaN

Approach

  1. dropna(how="all").

Solution

Python
import numpy as npimport pandas as pddf = pd.DataFrame({"name": ["Alex", np.nan, "Peter"], "age": [30, np.nan, np.nan]})print(df.dropna(how="all"))
Output
    name   age
0   Alex  30.0
2  Peter   NaN
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs