首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:输入类型不支持ufunc 'isfinite‘,并且无法安全地将输入强制为任何支持的类型

TypeError:输入类型不支持ufunc 'isfinite‘,并且无法安全地将输入强制为任何支持的类型
EN

Stack Overflow用户
提问于 2019-07-26 01:12:47
回答 1查看 9.8K关注 0票数 5

运行此行后,im收到以下错误: TypeError: ufunc 'isfinite‘不支持输入类型,并且根据强制转换规则''safe'’,无法将输入安全地强制转换为任何支持的类型

代码语言:javascript
复制
df[~(  (pd.np.isclose(df.Sizes.round(3), df.Volumes))  & (df['color'] == 'Blue')   )] 

我怎么才能修复它?

EN

回答 1

Stack Overflow用户

发布于 2019-07-27 00:22:05

代码语言:javascript
复制
In [152]: df=pd.DataFrame(np.arange(12.).reshape(4,3), columns=['one','two','three'])                        
In [153]: df.three[:] = ['a',np.nan,4,3.2]                                                                   
In [154]: df                                                                                                 
Out[154]: 
   one   two three
0  0.0   1.0     a
1  3.0   4.0   nan
2  6.0   7.0     4
3  9.0  10.0   3.2
In [155]: pd.np.isclose(df.one.round(3), df.two)                                                             
Out[155]: array([False, False, False, False])
In [156]: pd.np.isclose(df.one.round(3), df.three)                                                           
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-156-d99a19b1d9b5> in <module>
----> 1 pd.np.isclose(df.one.round(3), df.three)

/usr/local/lib/python3.6/dist-packages/numpy/core/numeric.py in isclose(a, b, rtol, atol, equal_nan)
   2520 
   2521     xfin = isfinite(x)
-> 2522     yfin = isfinite(y)
   2523     if all(xfin) and all(yfin):
   2524         return within_tol(x, y, atol, rtol)

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

对两个float32列的测试是有效的,但当其中一列是具有非数字值的对象数据类型时会引发此错误。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57207108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档