Is it possible to check for NaN in any arbitrary data structure in python?
Essentially, I would like a function, def containsNan(d)
which would return True
for any arbitrary standard python data structure d
, if there is any NaN
inside d
.
I looked into flattening d
, before doing some kind of apply()
, with math.isnan()
but there doesn't appear to be a general flatten that works on any d
.
Any ideas on what approach I should try?
This is very easy. Try using the pandas module for this job. It has a variety of functions for dealing with NaNs.
Check for null values:
df.isnull().values.any()
Count the number of null values:
df.isnull().sum().sum()
Note: This works in a pandas data frame. So if you want to work with a list or something convert it before doing this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.