I have a dataframe that can potentially contain NaN values. How do I find the NaNs and only the NaNs? Most suggestions suggest using df.isnull, but this returns None values as well. I only care about NaN.
Thanks
I have a dataframe that can potentially contain NaN values. How do I find the NaNs and only the NaNs? Most suggestions suggest using df.isnull, but this returns None values as well. I only care about NaN.
Thanks
To find NAN
values you can use:
df.isna().sum(axis='index') # or axis = 0
df.isna().sum(axis='columns') # or axis = 1
df.isna().sum().sum() # to find all nan values in df
NOTE
: df.isna()
will return a df(shape same as original df) with boolean values. Then you can use above 3 functions to evaluate nan
values.
TO COUNT ONLY NAN's
:
You can replace None
with random_str
, and then evaluate the NaN
Count.
new_df = df.astype(str).replace('None','Random_str')