Given a pandas dataframe containing possible NaN values scattered here and there:
Question: How do I determine which columns contain NaN values? In particular, can I get a list of the column names containing NaNs?
dataframenanpandaspython
Given a pandas dataframe containing possible NaN values scattered here and there:
Question: How do I determine which columns contain NaN values? In particular, can I get a list of the column names containing NaNs?
Best Answer
UPDATE: using Pandas 0.22.0
Newer Pandas versions have new methods 'DataFrame.isna()' and 'DataFrame.notna()'
as list of columns:
to select those columns (containing at least one
NaN
value):OLD answer:
Try to use isnull():
or as @root proposed clearer version:
to select a subset - all columns containing at least one
NaN
value: