问题描述
下午好,
我正在尝试获取一系列产品和类别(猫)的移动平均值(3 个月)。
Example = pd.DataFrame(
{'Date':['2019-01-01','2019-02-01','2019-03-01','2019-04-01','2019-01-01','2019-04-01'],'Store':['1','1','2',],'Cat':[1,1,2,1],'Sales':[3,3,4,7,9,}
)
Example = Example.set_index(["Store","Cat"]).fillna(False)
Example
所以你得到了列表。我曾尝试购买 Store 1 和 Cat。 1 但我不知道如何自动执行 bulce。
Example_med = Example.query(" Store == '1' and Cat == 1")
Example_med["M3"] = Example_med.Sales.rolling(window=3).mean()
Example_med
你能帮我吗?可能很容易,但我开始学习 python,我还没有在网上找到任何东西。
谢谢!
解决方法
抱歉,我的意思是我正在尝试获取一系列商店和类别(猫)的销售额的移动平均值(3 个月)。