Python Practice › Pandas Programs › Program 60
Is a column present?
Write a pandas program to check whether a column exists.
Output
True False
Approach
"col" in df.columns.
Solution
import pandas as pddf = pd.DataFrame({"name": ["Alex"], "salary": [50000]})print("salary" in df.columns, "bonus" in df.columns)Output
True False
Learn the concept
New to this topic? Read the lesson, then come back.