float(\'nan\')
results in Nan (not a number). But how do I check for it? Should be very easy, but I cannot find it.
here is an answer working with:
float('nan')
, numpy.nan
...A NaN implemented following the standard, is the only value for which the inequality comparison with itself should return True:
def is_nan(x):
return (x != x)
And some examples:
import numpy as np
values = [float('nan'), np.nan, 55, "string", lambda x : x]
for value in values:
print(f"{repr(value):<8} : {is_nan(value)}")
Output:
nan : True
nan : True
55 : False
'string' : False
at 0x000000000927BF28> : False