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.
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