Numpy NaN返回"nan" [英] Numpy NaN returning as 'nan'

查看:106
本文介绍了Numpy NaN返回"nan"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码的一部分:

This is a part of my code:

df['ColZ'] = np.where(
            (df['ColA'] == 'AA') & (df['ColB'] == 'BB'),
            'GOOD!',
            np.where((df['ColA'] == 'BB') & (df['ColB'] == 'AA'),
            'BAD...',
            np.nan))

但是'nan'填充为'nan'(字符串)而不是NaN.

But the 'nan's are populated as 'nan' (string) instead of NaN.

自然,df.isnull().any()返回False,因为'nan's已注册为字符串.

Naturally, df.isnull().any() returns False, because the 'nan's are registered as strings.

我哪里出错了?

推荐答案

也许尝试将nan替换为NaN:

df = df.replace('nan', np.nan)

这篇关于Numpy NaN返回"nan"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆