我遇到布林带算法问题。我想将此算法应用于我的时间序列数据。
代码:
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”变量的结果:
[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
答案 0 :(得分:1)
第一点是,正如我在评论中已经提到的,rolling_mean需要一个DataFrame 你可以通过插入行来实现这一点
speed = pd.DataFrame(data=speed)
在ave = ...
行之前。
尽管如此,您还错过了在rolling_std中定义window属性
(见:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.rolling_std.html)