栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Numpy isnan()在浮点数组上失败(适用于pandas数据框)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Numpy isnan()在浮点数组上失败(适用于pandas数据框)

np.isnan
可以应用于本机dtype的NumPy数组(例如np.float64):

In [99]: np.isnan(np.array([np.nan, 0], dtype=np.float64))Out[99]: array([ True, False], dtype=bool)

但是在应用于对象数组时引发TypeError:

In [96]: np.isnan(np.array([np.nan, 0], dtype=object))TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

由于您拥有Pandas,

pd.isnull
因此可以改用-它可以接受对象或本机dtypes的NumPy数组:

In [97]: pd.isnull(np.array([np.nan, 0], dtype=float))Out[97]: array([ True, False], dtype=bool)In [98]: pd.isnull(np.array([np.nan, 0], dtype=object))Out[98]: array([ True, False], dtype=bool)

请注意,

None
在对象数组中也将其视为空值。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/641022.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号