VOOZH about

URL: https://www.geeksforgeeks.org/python/check-for-nan-in-pandas-dataframe/

⇱ Check for NaN in Pandas DataFrame - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check for NaN in Pandas DataFrame

Last Updated : 30 Jan, 2023

NaN stands for Not A Number and is one of the common ways to represent the missing value in the data. It is a special floating-point value and cannot be converted to any other type than float. 

NaN value is one of the major problems in Data Analysis. It is very essential to deal with NaN in order to get the desired results.

👁 Image
 

Check for NaN Value in Pandas DataFrame

The ways to check for NaN in Pandas DataFrame are as follows: 

  • Check for NaN with isnull().values.any() method
  • Count the NaN Using isnull().sum() Method
  • Check for NaN Using isnull().sum().any() Method
  • Count the NaN Using isnull().sum().sum() Method

Method 1: Using isnull().values.any() method

Example: 

Output: 

True

It is also possible to get the exact positions where NaN values are present. We can do so by removing .values.any() from isnull().values.any() . 

Output: 

0 False
1 False
2 False
3 False
4 False
5 True
6 False
7 True
8 False
9 False
10 True
Name: Integers, dtype: bool

Method 2: Using isnull().sum() Method

Example: 

Output:

Number of NaN values present: 3

Method 3: Using isnull().sum().any() Method

Example: 

Output: 

True

To get the exact positions where NaN values are present, we can do so by removing .sum().any() from isnull().sum().any() . 

Method 4: Using isnull().sum().sum() Method

Example: 

Output:

Number of NaN values present: 8
Comment