How to find the number of null elements in a pandas DataFrame

Question:

I want a way to find the number of null elements in a DataFrame which gives just 1 number not another series or anything like that

Asked By: user16378160

||

Answers:

you could use pd.isnull() and sum:

df = pd.DataFrame([[1,1,1], [2,2,np.nan], [3,np.nan, np.nan]])
pd.isnull(df).values.sum()

which gives: 3

Answered By: Ezer K

This code chunk will help

# df is your dataframe
print(df.isnull().sum())
Answered By: L_Jay

You can simply get all null values from the dataframe and count them:

df.isnull().sum()

Or you can use individual column as well:

df['col_name'].isnull().sum()
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.