Categories
Python Answers

How to count the NaN values in a column in Python Pandas DataFrame?

Spread the love

To count the NaN values in a column in Python Pandas DataFrame, we call isna and sum.

For instance, we write

s = pd.Series([1,2,3, np.nan, np.nan])
count = s.isna().sum()

to create a series witth pd.Series.

The we call isna to return the isna values in the series.

And then we call sum to get the count of them.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *