Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More idiomatic version of "df.isnull().any().any()" w/ a Pandas DataFrame? [duplicate]

Tags:

python

pandas

df.isnull().any().any()

This line evaluates to a boolean True/False, as it checks whether a Pandas dataframe contains any NaN's in its rows or columns. Is there a more concise/idiomatic way of checking this?

like image 526
maxm Avatar asked Sep 30 '22 12:09

maxm


1 Answers

I think it's to use numpy's any:

In [11]: df = pd.DataFrame([[1, 2], [3, np.nan]])

In [12]: df.isnull().any().any()
Out[12]: True

In [13]: np.any(df.isnull())
Out[13]: True
like image 133
Andy Hayden Avatar answered Oct 03 '22 06:10

Andy Hayden