Python Practice › Pandas Programs › Program 87

Drop columns with missing values

EasyPandas Programs · 87 of 95

Write a pandas program to drop columns where at least one value is missing.

Advertisement
Output
   sr
0   1
1   2
2   3
3   4

Approach

  1. dropna(axis=1).

Solution

Python
import numpy as npimport pandas as pddf = pd.DataFrame({"sr": [1, 2, 3, 4], "name": ["Alex", np.nan, "Peter", "Klaus"], "age": [30, np.nan, 29, 22]})print(df.dropna(axis=1))
Output
   sr
0   1
1   2
2   3
3   4
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs