数据帧SMA计算

时间:2016-08-25 06:38:23

标签: python pandas dataframe

是否有任何简单的工具/库可以帮助我轻松计算数据帧的sma(..)?

                             GLD       SMA(5)
Date                                
2005-01-03 00:00:00+00:00  43.020000  Nan
2005-01-04 00:00:00+00:00  42.740002  Nan
2005-01-05 00:00:00+00:00  42.669998  Nan
2005-01-06 00:00:00+00:00  42.150002  Nan
2005-01-07 00:00:00+00:00  41.840000  ..
2005-01-10 00:00:00+00:00  41.950001  ..
2005-01-11 00:00:00+00:00  42.209999  ..
2005-01-12 00:00:00+00:00  42.599998  ..
2005-01-13 00:00:00+00:00  42.599998  ..
2005-01-14 00:00:00+00:00  42.320000  ..

1 个答案:

答案 0 :(得分:6)

df['SMA(5)'] = df.GLD.rolling(5).mean()
df

enter image description here