Python Practice › Pandas Programs › Program 87
Drop columns with missing values
Write a pandas program to drop columns where at least one value is missing.
Output
sr 0 1 1 2 2 3 3 4
Approach
dropna(axis=1).
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.