pandas AttributeError: 'list' 对象没有属性 'dtype'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35203484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 00:37:29  来源:igfitidea点击:

AttributeError: 'list' object has no attribute 'dtype'

pythonlistpandastimetime-series

提问by serenade

I have trouble with Bollinger Band algorithm. I want to apply this algorithm to my time series data.

我在使用布林带算法时遇到了麻烦。我想将此算法应用于我的时间序列数据。

The code:

编码:

length = 1440

dataframe = pd.DataFrame(speed)

ave = pd.stats.moments.rolling_mean(speed,length)

sd = pd.stats.moments.rolling_std(speed,length=1440)

upband = ave + (sd*2)

dnband = ave - (sd*2)

print np.round(ave,3), np.round(upband,3), np.round(dnband,3)

Input:

输入:

speed=[96.5, 97.0, 93.75, 96.0, 94.5, 95.0, 94.75, 96.0, 96.5, 97.0, 94.75, 97.5, 94.5, 96.0, 92.75, 96.5, 91.5, 97.75, 93.0, 96.5, 92.25, 95.5, 92.5, 95.5, 94.0, 96.5, 94.25, 97.75, 93.0]

Result of "ave" variable:

“ave”变量的结果:

[1440 rows x 1 columns] 0 0 NaN 1 NaN 2 NaN 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN 8 NaN 9 NaN 10 NaN 11 NaN 12 NaN 13 NaN 14 NaN 15 NaN 16 NaN 17 NaN

[1440 行 x 1 列] 0 0 NaN 1 NaN 2 NaN 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN 8 NaN 9 NaN 10 NaN 11 NaN 12 NaN 13 NaN 14 NaN 15 NaN 16 NaN 17 NaN

回答by Stefan Reinhardt

The first point is, as i allready mentioned in the comment rolling_mean needs a DataFrame you can achieve this by inserting the line

第一点是,正如我在评论中提到的rolling_mean需要一个DataFrame,你可以通过插入行来实现

speed = pd.DataFrame(data=speed) 

before the ave = ...line. Nonetheless you also missed to define the window attribute in rolling_std (See: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.rolling_std.html)

ave = ...行前。尽管如此,您还是错过了在 rolling_std 中定义 window 属性(参见:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.rolling_std.html )