週平均にアップサンプリングした xls の月次データがあります。1日が月曜日または火曜日に当たる場合、前月の先週を含めて、現在の月を再平均化する条件/関数が必要です。私はパンダのresample()を使用していました。
入力例: 月次データ
| 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 |
目標出力: 月曜日から火曜日の月の 1 日は、前の週を当月に追加します (週平均)
| 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 |