Python Practice › Pandas Programs › Program 60

Is a column present?

EasyPandas Programs · 60 of 95

Write a pandas program to check whether a column exists.

Advertisement
Output
True False

Approach

  1. "col" in df.columns.

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex"], "salary": [50000]})print("salary" in df.columns, "bonus" in df.columns)
Output
True False
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs