你看下是想要这样的结果吗
import pandas as pd
import numpy as np
#导入数据
data=pd.read_excel("D:\\360安全浏览器下载\\1606269162_843604.xlsx")
#计算简单的移动平均数
#在series下面有rolling方法可以对这个series进行滚动的移动平均计算
#只以X1为例进行说明
data["X1_3期移动平均"]=data["X1"].rolling(3).mean()
data["同比6期增长率"]=(data["X1_3期移动平均"]-data["X1_3期移动平均"].shift(6))/(data["X1_3期移动平均"].shift(6))
data["同比12期增长率"]=(data["X1_3期移动平均"]-data["X1_3期移动平均"].shift(12))/(data["X1_3期移动平均"].shift(12))
data["同比24期增长率"]=(data["X1_3期移动平均"]-data["X1_3期移动平均"].shift(24))/(data["X1_3期移动平均"].shift(24))
