Python TypeError:无法处理此类型->;对象

Python TypeError:无法处理此类型->;对象,python,pandas,matplotlib,Python,Pandas,Matplotlib,此代码不提供任何错误: r = df1.rolling(window = 32) r['msprice'].plot(color='red') 但是,该代码: r = df1.rolling(window = 32).apply(lambda x : x[1] - x[2]) r['msprice'].plot(color='red') 给出以下错误: ValueError: could not convert string to float: During handling of the

此代码不提供任何错误:

r = df1.rolling(window = 32)
r['msprice'].plot(color='red')
但是,该代码:

r = df1.rolling(window = 32).apply(lambda x : x[1] - x[2])
r['msprice'].plot(color='red')
给出以下错误:

ValueError: could not convert string to float:

During handling of the above exception, another exception occurred:
亲爱的

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

df['Quantity'].astype(float).rolling(window=7).mean().plot(figsize=(11,3))
在先前打印时的“数量”列中,它将值读取为字符串。将值转换为float或int是解决方案

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

致以最诚挚的问候

请向我们展示完整的错误信息。这是有原因的。另外,您正在使用Python3吗?TypeError:无法处理此类型->对象是的,我正在使用Python3。另外,您可以生成一个;事实上,这样更好,因为错误可能在其他地方。但至少我们需要回溯,我给我结果。但是当我使用lambda时,我犯了一个错误。我编辑了你的问题。不过,我们仍然需要实际的回溯;现在的一切都毫无用处。