Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫数据帧滚动,为什么窗口必须是非负的?_Python_Pandas - Fatal编程技术网

Python 熊猫数据帧滚动,为什么窗口必须是非负的?

Python 熊猫数据帧滚动,为什么窗口必须是非负的?,python,pandas,Python,Pandas,我正在处理金融交易数据,我想计算未来10天价格的平均值/标准值 但当我调用rolling方法时,它出现了一个错误:窗口必须是非负的 import pandas as pd a=pd.Series([1,2,9, 3,8,12,15]) a.rolling(2).mean() # this is ok a.rolling(-2).mean() # this failed, as window cant be non-negative, but i want to calculate the

我正在处理金融交易数据,我想计算未来10天价格的平均值/标准值

但当我调用rolling方法时,它出现了一个错误:窗口必须是非负的

import pandas as pd
a=pd.Series([1,2,9, 3,8,12,15])
a.rolling(2).mean()   # this is ok
a.rolling(-2).mean()  # this failed, as window cant be non-negative, but i want to calculate the future 2 window's mean, i think it's a common operation, why it failed?
# i want to calcualte the future 2 windows's mean, for example, the first output should be 5.5, as the future 2 window is [2,9]
我认为对于差分、移位法,窗口大小可以是非负的,为什么不能滚动


有什么方法可以实现这个函数吗?

你能组成一个小数据集并显示预期的输出吗?@ScottBoston补充道,thx for Advice你希望从滚动(-2)中得到什么。mean()你能显示你的输出序列吗?两种建议的方法:反转,打开窗口,然后再次反转,或者使用shift()。详情如下: