How to check if one or multiple Pandas columns exist?

In today’s data wrangling tutorial, we’ll learn how to use Python to check how to find out if one or multiple columns exist in a DataFrame. This can be helpful after exporting a very wide Data set, or before joining two DataFrames.

Create the Python DataFrame

We’ll first go ahead and create a very simple DataFrame – feel free to use it in order to follow along this example.

# import the Pandas library
import pandas as pd

# define your data
cols = ['emp_id', 'name', 'target', 'achievement']
data = [['1', 'John Sales', 450, 500], [2,'Debbie Financials', pd.NA, pd.NA]]

sales = pd.DataFrame (data=data, columns=cols)


Let us now look into the DataFrame that we have just created:

01John Sales450500
12Debbie Financials<NA><NA

Check if a column exist in a DataFrame

To find whether a specific column exists across a Pandas DataFrame rows you can use the following snippet:

# column exists in row
print('target' in sales)

' This will return a boolean True

Alternatively, use the following code:

col = 'target'

'This will return a Series object

Find if multiple columns are contained in your DataFrame

To check if your DataFrame contains multiple specific columns, pass a list to the pd.Series method as shown below and check against your DataFrame columns index

subset = ['target', 'achievement']


Result will be a Series containing boolean values.

0    True
1    True
dtype: bool

Find if a column contains a specific string

To find the rows that exists and matches a specific string pattern in your DataFrame column:

mask = 


Result will be:

01John Sales450500

Pandas – check if a row has empty values

Last case for today is to find whether specific column has empty values:

# column has empty values

This will return the number of empty values in the column – in this case 1.

Additional Learning