I want to find the number of NaN in each column of my data.
Question
Answer
Use the isna() method (or it's alias isnull() which is also compatible with older pandas versions < 0.21.0) and then sum to count the NaN values. For one column:
>>> s = pd.Series([1,2,3, np.nan, np.nan])
>>> s.isna().sum() # or s.isnull().sum() for older pandas versions
2
For several columns, this also works:
>>> df = pd.DataFrame({'a':[1,2,np.nan], 'b':[np.nan,1,np.nan]})
>>> df.isna().sum()
a 1
b 2
dtype: int64