How to check for NaN values in Python

3 Answers

0 votes
import math
import numpy as np

b = math.nan
print(np.isnan(b))




'''
run:

True

'''

 



answered Apr 20, 2021 by avibootz
0 votes
import numpy as np

arr = np.array([4, 9, np.NaN, 3])

print(np.isnan(arr))




'''
run:

[False False  True False]

'''

 



answered Apr 20, 2021 by avibootz
0 votes
import math

def isNaN(b):
    return b != b


b = math.nan

print(isNaN(b))





'''
run:

True

'''

 



answered Apr 20, 2021 by avibootz
...