Python np.where子句后面的pandas中不识别NaN。为什么?还是一只虫子?

Python np.where子句后面的pandas中不识别NaN。为什么?还是一只虫子?,python,numpy,pandas,Python,Numpy,Pandas,np.where子句后面的pandas中不识别NaN。为什么?还是一只虫子 此代码的最后一行应为“True” 如果查看where的结果,您可以了解原因: >>> np.where(a.isnull(), np.nan, "Hello") array([u'Hello', u'nan'], dtype='<U32') 是否有一个np.where函数允许处理这些事情?或者有没有其他方法来重写它以使其工作? >>> np.where(a.isn

np.where子句后面的pandas中不识别NaN。为什么?还是一只虫子

此代码的最后一行应为“True”


如果查看
where
的结果,您可以了解原因:

>>> np.where(a.isnull(), np.nan, "Hello")
array([u'Hello', u'nan'], 
      dtype='<U32')

是否有一个np.where函数允许处理这些事情?或者有没有其他方法来重写它以使其工作?
>>> np.where(a.isnull(), np.nan, "Hello")
array([u'Hello', u'nan'], 
      dtype='<U32')
>>> b["X"] = a.isnull().map({True: np.nan, False: "Hello"})
>>> b
   0      X
0  a  Hello
1  b    NaN
>>> b.X.isnull()
0    False
1     True
Name: X, dtype: bool