Pandas 为什么我会得到“一个”;ValueError:数据类型<;类别';numpy.object'&燃气轮机;并非不准确。”;在使用polyfit函数时?
我正试图为我的数据绘制一条趋势线。然而,我得到了错误Pandas 为什么我会得到“一个”;ValueError:数据类型<;类别';numpy.object'&燃气轮机;并非不准确。”;在使用polyfit函数时?,pandas,numpy,matplotlib,trendline,dtype,Pandas,Numpy,Matplotlib,Trendline,Dtype,我正试图为我的数据绘制一条趋势线。然而,我得到了错误 ValueError: data type <class 'numpy.object_'> not inexact. 它说, ValueError: data type <class 'numpy.object_'> not inexact. ValueError:数据类型不准确。 如果x,则从系列派生的数组是对象数据类型,则会产生错误: In [67]: np.polyfit(np.arange(3).ast
ValueError: data type <class 'numpy.object_'> not inexact.
它说,
ValueError: data type <class 'numpy.object_'> not inexact.
ValueError:数据类型不准确。
如果x
,则从系列
派生的数组是对象
数据类型,则会产生错误:
In [67]: np.polyfit(np.arange(3).astype(object),np.arange(3),1)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-67-787351a47e03> in <module>
----> 1 np.polyfit(np.arange(3).astype(object),np.arange(3),1)
<__array_function__ internals> in polyfit(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/numpy/lib/polynomial.py in polyfit(x, y, deg, rcond, full, w, cov)
605 # set rcond
606 if rcond is None:
--> 607 rcond = len(x)*finfo(x.dtype).eps
608
609 # set up least squares equation for powers of x
/usr/local/lib/python3.6/dist-packages/numpy/core/getlimits.py in __new__(cls, dtype)
380 dtype = newdtype
381 if not issubclass(dtype, numeric.inexact):
--> 382 raise ValueError("data type %r not inexact" % (dtype))
383 obj = cls._finfo_cache.get(dtype, None)
384 if obj is not None:
ValueError: data type <class 'numpy.object_'> not inexact
[67]中的:np.polyfit(np.arange(3).astype(object),np.arange(3,1)
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在里面
---->1 np.polyfit(np.arange(3).aType(object),np.arange(3),1)
采用polyfit(*args,**kwargs)
/polyfit中的usr/local/lib/python3.6/dist-packages/numpy/lib/polynomy.py(x、y、deg、rcond、full、w、cov)
605#设置rcond
606如果rcond为无:
-->607 rcond=len(x)*finfo(x.dtype).eps
608
609#为x的幂建立最小二乘方程
/usr/local/lib/python3.6/dist-packages/numpy/core/getlimits.py in\uuuuuuu new\uuuuuuuuu(cls,dtype)
380数据类型=新数据类型
381如果不是issubclass(数据类型,数值不精确):
-->382 raise VALUERROR(“数据类型%r不精确”%(数据类型))
383 obj=cls.\u finfo\u cache.get(数据类型,无)
384如果obj不是无:
ValueError:数据类型不准确
像这样的函数需要数字数据类型数组。首先清理数据帧 给我们更多的信息
data5.d类型
,完整错误回溯
,x
是一个系列
。那么x.to_numpy()
呢shape
,dtype
?在您的响应之后,我将数据从object转换为float。我对x和y都使用了“x=data5['usgdp'].astype(str).astype(float)”。它成功了。谢谢你,我的大部分数据被格式化为Int32
,而不是int
——谢谢你的提示。
In [67]: np.polyfit(np.arange(3).astype(object),np.arange(3),1)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-67-787351a47e03> in <module>
----> 1 np.polyfit(np.arange(3).astype(object),np.arange(3),1)
<__array_function__ internals> in polyfit(*args, **kwargs)
/usr/local/lib/python3.6/dist-packages/numpy/lib/polynomial.py in polyfit(x, y, deg, rcond, full, w, cov)
605 # set rcond
606 if rcond is None:
--> 607 rcond = len(x)*finfo(x.dtype).eps
608
609 # set up least squares equation for powers of x
/usr/local/lib/python3.6/dist-packages/numpy/core/getlimits.py in __new__(cls, dtype)
380 dtype = newdtype
381 if not issubclass(dtype, numeric.inexact):
--> 382 raise ValueError("data type %r not inexact" % (dtype))
383 obj = cls._finfo_cache.get(dtype, None)
384 if obj is not None:
ValueError: data type <class 'numpy.object_'> not inexact