小编Bo *_*Wan的帖子

dataframe.apply(lambda x: x is np.nan) 不起作用

所以基本上数据框中的列有 Nan 和 float,我想使用 apply 来计算列中的值。如果值为nan,则返回else,计算。

但看起来x is np.nanlambda 并没有给我正确的答案。这是一个例子

In[6]: df = pd.DataFrame({'A': [np.nan, np.nan, np.nan]})

In[7]: df.A.apply(lambda x: x is np.nan)
Out[7]: 
0    False
1    False
2    False
Run Code Online (Sandbox Code Playgroud)

有谁知道原因吗?

python numpy pandas

1
推荐指数
1
解决办法
1360
查看次数

标签 统计

numpy ×1

pandas ×1

python ×1