Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas - check if ALL values are NaN in Series

I have a data series which looks like this:

print mys  id_L1 2       NaN 3       NaN 4       NaN 5       NaN 6       NaN 7       NaN 8       NaN 

I would like to check is all the values are NaN.

My attempt:

pd.isnull(mys).all() 

Output:

True 

Is this the correct way to do it?

like image 757
Boosted_d16 Avatar asked Oct 15 '15 11:10

Boosted_d16


People also ask

Is NaN in pandas series?

The official documentation for pandas defines what most developers would know as null values as missing or missing data in pandas. Within pandas, a missing value is denoted by NaN .

How do you know if a series is null?

Call the isnull() function of the Series object. It returns a boolean Series of the same size. Each True value in this boolean Series indicates that the corresponding value in the Original Series (selected column) is NaN. Check if all values in the boolean Series are True or not.

How do you check if all columns are null in pandas?

By using isnull(). values. any() method you can check if a pandas DataFrame contains NaN / None values in any cell (all rows & columns ).


1 Answers

Yes, that's correct, but I think a more idiomatic way would be:

mys.isnull().all() 
like image 60
Andrew Rosenfeld Avatar answered Sep 21 '22 04:09

Andrew Rosenfeld