使用熊猫移动平均2天时间

时间:2020-09-27 06:23:57

标签: python pandas moving-average

我有一个数据框df,我想用窗口5来计算接下来2天的移动平均值。然后,我希望将结果存储在Python中的变量中:

 date                count

 08052020            50
 08152020            10
 08252020            30
 09052020            10
 09152020            15
 09252020            5

这就是我在做什么:

 count = df['new'] = df['count'].rolling(2).mean()
 print(count)

任何见识都会受到赞赏。

已更新所需的输出:

 count = [23, 14]
       

         

1 个答案:

答案 0 :(得分:3)

我认为您需要:

df['new'] = df['count'].rolling(5).mean()

count = df["new"].dropna().to_list()

print(count)

输出:

[23.0, 14.0]