想要將df.Month爆炸爲周並將數量平均分配到周。周從星期一開始。將月份的數量平均分配到周(2)
DF
Country Item Month Qty
-------------------------------------------
0 New Zealand Apple 2017-10-31 100
1 Puerto Rico Banana 2017-11-30 200
2 France Apple 2017-10-31 400
...
期望的輸出是:
Country Item Week Qty
-------------------------------------------
0 New Zealand Apple 2017-10-01 20
1 New Zealand Apple 2017-10-08 20
2 New Zealand Apple 2017-10-15 20
3 New Zealand Apple 2017-10-22 20
4 New Zealand Apple 2017-10-29 20
5 Puerto Rico Banana 2017-11-05 50
6 Puerto Rico Banana 2017-11-12 50
7 Puerto Rico Banana 2017-11-19 50
8 Puerto Rico Banana 2017-11-26 50
9 France Apple 2017-10-01 80
10 France Apple 2017-10-08 80
...
使用專爲週數據幀: mondays = pd.Series(pd.date_range(first_day, last_day, freq='W-Mon')) weeks = pd.DataFrame({'Week':mondays})
2)周
Week
----------
0 2017-10-01
1 2017-10-08
2 2017-10-15
3 2017-10-22
4 2017-10-29
5 2017-11-05
6 2017-11-12
7 2017-11-19
8 2017-11-26
...
這是對問題的擴展:Distribute month's quantity equally into weeks。
'DF1 = df1.drop_duplicates( '月')'與之前的解決方案不起作用? – jezrael