类型错误:无法处理此类型>对象

2024-09-19 23:38:11 发布

您现在位置:Python中文网/ 问答频道 /正文

此代码没有错误:

r = df1.rolling(window = 32)
r['msprice'].plot(color='red')

但是,该代码:

^{pr2}$

给出以下错误:

ValueError: could not convert string to float:

During handling of the above exception, another exception occurred:

Tags: 代码convertplot错误exceptionnotredwindow
1条回答
网友
1楼 · 发布于 2024-09-19 23:38:11

亲爱的

我也有过类似的经历,下面是我的解决方案。在

df['Quantity'].astype(float).rolling(window=7).mean().plot(figsize=(11,3))

在前面绘制的Quantity列中,它以字符串形式读取值。解决方案是将值转换为float或int。在

谨致问候

相关问题 更多 >