我有 xls 中的月度数据,我将其上采样为每周平均值。现在我需要一个条件/函数来包括上个月的最后一周,如果第一天落在星期一或星期二并重新计算当前月份的平均值。我正在使用熊猫重采样()。
样本输入:月度数据
| Date | Store | Fruit | Quantity |
|:---------:|:--------:|:-------:|:----------:|
|Jan 2021 | A-Mart | Apple | 70 |
|Feb 2021 | A-Mart | Apple | 60 |
|Mar 2021 | A-Mart | Apple | 90 |
|Apr 2021 | A-Mart | Apple | 40 |
|Jan 2021 | A-Mart | Banana | 40 |
|Feb 2021 | A-Mart | Banana | 100 |
|Mar 2021 | A-Mart | Banana | 80 |
|Apr 2021 | A-Mart | Banana | 20 |
当前输出:每周数据“星期日”平均
| Date | Store | Fruit | Quantity |
|:---------:|:--------:|:-------:|:----------:|
|03/Jan/21 | A-Mart | Apple | 14 |
|10/Jan/21 | A-Mart | Apple | 14 |
|17/Jan/21 | A-Mart | Apple | 14 |
|24/Jan/21 | A-Mart | Apple | 14 |
|31/Jan/21 | A-Mart | Apple | 14 |
|03/Feb/21 | A-Mart | Apple | 15 |
|10/Feb/21 | A-Mart | Apple | 15 |
|17/Feb/21 | A-Mart | Apple | 15 |
|24/Feb/21 | A-Mart | Apple | 15 |
|07/Mar/21 | A-Mart | Apple | 22.5 |
|14/Mar/21 | A-Mart | Apple | 22.5 |
|21/Mar/21 | A-Mart | Apple | 22.5 |
|28/Mar/21 | A-Mart | Apple | 22.5 |
|04/Apr/21 | A-Mart | Apple | 10 |
|11/Apr/21 | A-Mart | Apple | 10 |
|18/Apr/21 | A-Mart | Apple | 10 |
|25/Apr/21 | A-Mart | Apple | 10 |
|03/Jan/21 | A-Mart | Banana | 8 |
|10/Jan/21 | A-Mart | Banana | 8 |
|17/Jan/21 | A-Mart | Banana | 8 |
|24/Jan/21 | A-Mart | Banana | 8 |
|31/Jan/21 | A-Mart | Banana | 8 |
|03/Feb/21 | A-Mart | Banana | 25 |
|10/Feb/21 | A-Mart | Banana | 25 |
|17/Feb/21 | A-Mart | Banana | 25 |
|24/Feb/21 | A-Mart | Banana | 25 |
|07/Mar/21 | A-Mart | Banana | 20 |
|14/Mar/21 | A-Mart | Banana | 20 |
|21/Mar/21 | A-Mart | Banana | 20 |
|28/Mar/21 | A-Mart | Banana | 20 |
|04/Apr/21 | A-Mart | Banana | 5 |
|11/Apr/21 | A-Mart | Banana | 5 |
|18/Apr/21 | A-Mart | Banana | 5 |
|25/Apr/21 | A-Mart | Banana | 5 |
目标输出:周一至周二的第一个月将前一周添加到当前月份(每周平均)
| Date | Store | Fruit | Quantity |
|:---------:|:--------:|:-------:|:----------:|
|03/Jan/21 | A-Mart | Apple | 14 |
|10/Jan/21 | A-Mart | Apple | 14 |
|17/Jan/21 | A-Mart | Apple | 14 |
|24/Jan/21 | A-Mart | Apple | 14 |
|31/Jan/21 | A-Mart | Apple | 14 |
|31/Jan/21 | A-Mart | Apple | 12 |
|03/Feb/21 | A-Mart | Apple | 12 |
|10/Feb/21 | A-Mart | Apple | 12 |
|17/Feb/21 | A-Mart | Apple | 12 |
|24/Feb/21 | A-Mart | Apple | 12 |
|24/Feb/21 | A-Mart | Apple | 18 |
|07/Mar/21 | A-Mart | Apple | 18 |
|14/Mar/21 | A-Mart | Apple | 18 |
|21/Mar/21 | A-Mart | Apple | 18 |
|28/Mar/21 | A-Mart | Apple | 18 |
|04/Apr/21 | A-Mart | Apple | 10 |
|11/Apr/21 | A-Mart | Apple | 10 |
|18/Apr/21 | A-Mart | Apple | 10 |
|25/Apr/21 | A-Mart | Apple | 10 |
|03/Jan/21 | A-Mart | Banana | 8 |
|10/Jan/21 | A-Mart | Banana | 8 |
|17/Jan/21 | A-Mart | Banana | 8 |
|24/Jan/21 | A-Mart | Banana | 8 |
|31/Jan/21 | A-Mart | Banana | 8 |
|31/Jan/21 | A-Mart | Banana | 20 |
|03/Feb/21 | A-Mart | Banana | 20 |
|10/Feb/21 | A-Mart | Banana | 20 |
|17/Feb/21 | A-Mart | Banana | 20 |
|24/Feb/21 | A-Mart | Banana | 20 |
|24/Feb/21 | A-Mart | Banana | 16 |
|07/Mar/21 | A-Mart | Banana | 16 |
|14/Mar/21 | A-Mart | Banana | 16 |
|21/Mar/21 | A-Mart | Banana | 16 |
|28/Mar/21 | A-Mart | Banana | 16 |
|04/Apr/21 | A-Mart | Banana | 5 |
|11/Apr/21 | A-Mart | Banana | 5 |
|18/Apr/21 | A-Mart | Banana | 5 |
|25/Apr/21 | A-Mart | Banana | 5 |