pandas check if value exists in column code example

Example 1: only keep rows of a dataframe based on a column value

df.loc[df['column_name'] == some_value]

Example 2: check if column exists in dataframe

if 'A' in df.columns:

Example 3: find nan values in a column pandas

df['your column name'].isnull().sum()

Example 4: pandas check if value in column is in a list

df_new[df_new['l_ext'].isin([31, 22, 30, 25, 64])]

Example 5: check if column exists in dataframe python

if 'A' in df:

Example 6: check if value is in series pandas

In [21]: s.unique()
Out[21]: array(['a', 'b', 'c'], dtype=object)

In [22]: 'a' in s.unique()
Out[22]: True