How to check if any value is NaN in a Pandas DataFrame

0 votes
In Python Pandas, what's the best way to check whether a DataFrame has one (or more) NaN values?

I know about the function pd.isnan, but this returns a DataFrame of booleans for each element.
Jun 15, 2020 in Python by kartik
• 37,520 points
4,926 views

1 answer to this question.

0 votes

Hello @kartik,

If you need to know how many rows there are with "one or more NaNs":

df.isnull().T.any().T.sum()

Or if you need to pull out these rows and examine them:

nan_rows = df[df.isnull().T.any().T]

Hope this helps!

Thank You!!

answered Jun 15, 2020 by Niroj
• 82,800 points

Related Questions In Python

0 votes
1 answer

How to find if a value exists in Pandas dataframe?

Try this:​ for name in df['Name']: ...READ MORE

answered Apr 8, 2019 in Python by Tina
13,189 views
0 votes
2 answers

How to check if a csv file is empty in pandas?

Try this: df = pd.DataFrame(columns=['Name', 'ID', 'Department']) if df.empty ...READ MORE

answered Jul 1, 2019 in Python by Bob
15,814 views
+1 vote
1 answer

How to check if a string is null in python

I want to check if any NULL ...READ MORE

answered Mar 9, 2022 in Python by satish

edited Mar 5 24,018 views
0 votes
1 answer

How to check if a substring is present in a string using Python?

To check if the substring exists in ...READ MORE

answered May 9, 2019 in Python by Sharan
1,637 views