Aporia has been acquired by Coralogix, instantly bringing AI security and reliability to thousands of enterprises | Read the announcement

Back to Blog
How-To

How to Check If a Column Exists in a DataFrame

Aporia Team Aporia Team 1 min read Sep 06, 2022

A DataFrame might contain hundreds of even thousands of columns. It is not possible to visually check if a column exists in such DataFrames.

In this short how-to article, we will learn a practical way of performing this operation in Pandas and PySpark DataFrames.

check-if-column-exists-in-dataframe

Pandas

We can use the in keyword for this task.

"f128" in df.columns
True

It returns True if the given column exists in the DataFrame.

PySpark

The exact same operation works in PySpark as well.

"f128" in df.columns
True

This question is also being asked as:

  • Check for existence of multiple columns

People have also asked for:

Rate this article

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

On this page

Blog
Building a RAG app?

Consider AI Guardrails to get to production faster

Learn more
Table of Contents

Related Articles