Check if Column Exists in pandas DataFrame in Python (Example) | How to Search & Find Variable Name

Check if Column Exists in pandas DataFrame in Python (Example) | How to Search & Find Variable Name

Statistics Globe

1 год назад

212 Просмотров

How to test whether a column name exists in a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/check-if-column-exists-in-pandas-dataframe-python
Python code of this video:

import pandas as pd # Import pandas

data = pd.DataFrame({'x1':range(1, 6), # Create example DataFrame
'x2':[1, 1, 1, 1, 1],
'x3':[5, 2, 6, 8, 1]})
print(data) # Print example DataFrame

print('x1' in data.columns) # Test for existing column
# True

print('some_name' in data.columns) # Test for non-existing column
# False

Follow me on Social Media:
Facebook – Statistics Globe Page: https://www.facebook.com/statisticsglobecom/
Facebook – R Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
Facebook – Python Programming Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobepython
LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn – R Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
LinkedIn – Python Programming Group for Discussions & Questions: https://www.linkedin.com/groups/12673534/
Twitter: https://twitter.com/JoachimSchork

Music by bensound.com

Тэги:

#statistics_globe #statisticsglobe.com #statistical_programming #python_programming #statistics #python_programming_language #python_statistics #jupyter_notebook #python_language #python_tutorial #learn_python #python_code #python_programming_tutorial #data_science #data_scientist #learn_data_science #Check_if_Column_Exists_in_pandas_DataFrame_in_Python_(Example) #Search_&_Find_Variable_Name
Ссылки и html тэги не поддерживаются


Комментарии:

@kiyalight94
@kiyalight94 - 28.11.2022 19:43

I appreciate your effort. Thank you!

Ответить