我想计算每年按(APMC,商品)分组的模式价格的滚动平均值,窗口长度为当年的月数。根据我的解决方案,我得到了所有南的。数据集如下:
APMC | Commodity | qtl _weight| min_price | max_price | modal_price | district_name | Year | Month
date
2014-12-01 Akole bajri 40 1375 1750 1563 Ahmadnagar 2014 12
2014-12-01 Akole paddy-unhusked 346 1400 1800 1625 Ahmadnagar 2014 12
2014-12-01 Akole wheat 55 1500 1900 1675 Ahmadnagar 2014 12
2014-12-01 Akole bhagar/vari 59 2000 2600 2400 Ahmadnagar 2014 12
2014-12-01 Akole gram 9 3200 3300 3235 Ahmadnagar 2014 12
2014-12-01 Jamkhed cotton 44199 3950 4033 3991 Ahmadnagar 2014 12
2014-12-01 Jamkhed bajri 846 1300 1488 1394 Ahmadnagar 2014 12
2014-12-01 Jamkhed wheat(husked) 155 1879 2231 2055 Ahmadnagar 2014 12
2014-12-01 Kopar gram 421 1983 2698 2463 Ahmadnagar 2014 12
2014-12-01 Kopar greengram 18 6734 7259 6759 Ahmadnagar 2014 12
2014-12-01 Kopar soybean 1507 2945 3247 3199 Ahmadnagar 2014 12
2016-11-01 Sanga wheat(husked) 222 1730 2173 1994 Ahmadnagar 2016 11
每个APMC有6万行,商品集群三年的月数不同(201420152016)。你知道吗
我想你应该为每年x APMC x商品分组,然后用
.expanding().mean()
来计算每组的滚动平均数。因为你的数据似乎是每月的,这将是一个滚动平均每月。你知道吗样本数据
代码
输出
由于输出具有原始
DataFrame
的索引,因此如果需要,可以加入结果。你知道吗我不知道你是否需要分组,但你可以:
但打了这个之后,我觉得你的“那一年的月数”有点不对劲。你知道吗
不管怎样,这不是你想要的,但解决了你的问题。你知道吗
相关问题 更多 >
编程相关推荐