Python judges whether there is NaN in the data

def test():

    a = [1,1,1,1,1,1,np.nan,1,1,1,1,1]
    b = np.isnan(a)
    print(b)
    if True in b: # 检查 b 里面有没有 True
        print("a has nan.")
    
if __name__ == '__main__':
    test()
    

result:

[False False False False False False  True False False False False False]
a has nan.

In the position of nan, it is True

Guess you like

Origin blog.csdn.net/stellao_o/article/details/123022447