VOOZH about

URL: https://www.geeksforgeeks.org/python/count-nan-or-missing-values-in-pandas-dataframe/

⇱ Count NaN or missing values in Pandas DataFrame - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Count NaN or missing values in Pandas DataFrame

Last Updated : 23 Jan, 2025

In this article, we will see how to Count NaN or missing values in Pandas DataFrame using isnull() and sum() method of the DataFrame.

1. DataFrame.isnull() Method

DataFrame.isnull() function detect missing values in the given object. It return a boolean same-sized object indicating if the values are NA. Missing values gets mapped to True and non-missing value gets mapped to False.

Syntax: DataFrame.isnull()

Let's create a pandas dataframe.


Output
 Name Age Place College
a Ankit 22.0 Up Geu
b Ankita NaN Delhi NaN
c Rahul 16.0 Tokyo Abes
d Simran 41.0 Delhi Gehu
e Shaurya NaN Delhi ...

Example 1 : Count total NaN at each column in DataFrame using isnull() method


Output
Boolean DataFrame:
 Name Age Place College
a False False False False
b False True False True
c False False False False
d False False False False
e False True Fal...

2. Dataframe.sum() Method

Dataframe.sum() function return the sum of the values for the requested axis. If the input is index axis then it adds all the values in a column and repeats the same for all the columns and returns a series containing the sum of all the values in each column.

Syntax: DataFrame.sum()

Example 2 : Count total NaN in DataFrame using Dataframe.sum() method


Output
Boolean DataFrame:
 Name Age Place College
a False False False False
b False True False True
c False False False False
d False False False False
e False True Fal...
Comment