AttributeError:“列表"对象没有属性"dtype" [英] AttributeError: 'list' object has no attribute 'dtype'

查看:244
本文介绍了AttributeError:“列表"对象没有属性"dtype"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

代码:

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)

输入:

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]

"ave"变量的结果:

Result of "ave" variable:

[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钠 16 NaN 17 NaN

[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

推荐答案

第一点是,正如我在评论中已经提到的,rolling_mean需要一个DataFrame 您可以通过插入

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

speed = pd.DataFrame(data=speed) 

ave = ...行之前. 但是,您也错过了在rolling_std中定义窗口属性 (请参阅: http://pandas.pydata.org/pandas- docs/stable/generated/pandas.rolling_std.html )

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)

这篇关于AttributeError:“列表"对象没有属性"dtype"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆