close

How to find which columns contain any NaN value in Pandas dataframe

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to find which columns contain any NaN value in Pandas dataframe in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to find which columns contain any NaN value in Pandas dataframe?

  1. How to find which columns contain any NaN value in Pandas dataframe?

    You can use df.isnull().sum(). It shows all columns and the total NaNs of each feature.

  2. find which columns contain any NaN value in Pandas dataframe

    You can use df.isnull().sum(). It shows all columns and the total NaNs of each feature.

Method 1

You can use df.isnull().sum(). It shows all columns and the total NaNs of each feature.

Method 2

I had a problem where I had to many columns to visually inspect on the screen so a shortlist comp that filters and returns the offending columns is

nan_cols = [i for i in df.columns if df[i].isnull().any()]

if that’s helpful to anyone

Adding to that if you want to filter out columns having more nan values than a threshold, say 85% then use

nan_cols85 = [i for i in df.columns if df[i].isnull().sum() > 0.85*len(data)]

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read