【发布时间】:2015-04-17 07:51:10
【问题描述】:
print type (analysis['SMA_22'])
<class 'pandas.core.series.Series'>
analysis['SMA_22'].fillna('0').pct_change()
TypeError: unsupported operand type(s) for /: 'str' and 'str'
analysis.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 619 entries, 2012-12-03 00:00:00 to 2015-04-16 00:00:00
Data columns (total 3 columns):
SMA_22 598 non-null float64
dtypes: float64(2), object(1)
有人知道为什么吗?
Edit1:按要求显示 .info()
【问题讨论】:
-
“SMA_22”的数据类型是什么?你能显示来自
analysis.info()的输出吗? -
analysis.info()
DatetimeIndex:619 个条目,2012-12-03 00:00:00 到 2015-04-16 00:00: 00 数据列(共 3 列):SMA_22 598 非空 float64 dtypes:float64(2), object(1) -
请在您的问题中编辑附加信息,谢谢
-
错误很明显,它认为该列的 dtype 是字符串,您可以尝试将其转换为浮点数然后再试一次:
analysis[SMA_22'] = analysis[SMA_22'].astype(np.float64) -
SMA_22 598 non-null float64, analysis['SMA_22'].fillna('0').pct_change() 仍然失败并出现同样的错误。
标签: python python-2.7 pandas