This will work:
if 'A' in df:
But for clarity, I’d probably write it as:
if 'A' in df.columns:
More Related Contents:
- Pandas conditional creation of a series/dataframe column
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- How to unnest (explode) a column in a pandas DataFrame, into multiple rows
- How to split a dataframe string column into two columns?
- Error: pandas hashtable keyerror
- Remove unwanted parts from strings in a column
- Comparing two dataframes and getting the differences [duplicate]
- How to filter rows containing a string pattern from a Pandas dataframe [duplicate]
- Accessing Pandas column using squared brackets vs using a dot (like an attribute)
- Get the name of a pandas DataFrame
- Why does my Pandas DataFrame not display new order using `sort_values`?
- python/pandas: convert month int to month name
- How can I remove all non-numeric characters from all the values in a particular column in pandas dataframe?
- Combining two Series into a DataFrame in pandas
- pandas unique values multiple columns
- How to find which columns contain any NaN value in Pandas dataframe
- Python Pandas Group by date using datetime data
- Converting a column within pandas dataframe from int to string
- Pandas – dataframe groupby – how to get sum of multiple columns
- pandas comparison raises TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
- Mapping ranges of values in pandas dataframe [duplicate]
- pandas: combine two columns in a DataFrame
- How do I filter a pandas DataFrame based on value counts?
- Convert month int to month name in Pandas
- Pandas query function not working with spaces in column names
- Remove NaN values from pandas dataframe and reshape table [duplicate]
- Remove ends of string entries in pandas DataFrame column
- Collapsing rows in a Pandas dataframe if all rows have only one value in their columns
- Pythonic/efficient way to strip whitespace from every Pandas Data frame cell that has a stringlike object in it
- Difference between df[x], df[[x]], df[‘x’] , df[[‘x’]] and df.x