My company uses a 5-4-4 calendar for reporting purposes. Each month (aka period) is 4-weeks long, except every first month is 5-weeks long.
Pandas seems to have good support for custom calendar periods and found this documentation too.
I'm creating Period column from Week and Year using below code
dff['Period'] = pd.to_datetime(dff["Week ID"].astype("str") + "-0", format="%Y%U-%w").dt.month
dff['Period'] ='Period ' + dff['Period'].astype(str).str.zfill(2)
However my company is using 5-4-4 format for period i.e.
- First 5 weeks [Wk01 to Wk05] should be considered as Period 1
- next 4 weeks [Wk06 to Wk09] should be considered as Period 2
- next 4 weeks [Wk10 to Wk13] should be considered as Period 3
again
- next 5 weeks [Wk14 to Wk18] should be considered as Period 4
- next 4 weeks [Wk19 to Wk22] should be considered as Period 5
- next 4 weeks [Wk23 to Wk26] should be considered as Period 6
and so on for every year.......
Current output
Year Period Week Week ID Site
2020 Period 01 Wk01 202001 ABC
2020 Period 01 Wk02 202002 ABC
2020 Period 01 Wk03 202003 ABC
2020 Period 01 Wk04 202004 ABC
2020 Period 02 Wk05 202005 ABC
2020 Period 02 Wk06 202006 ABC
2020 Period 02 Wk07 202007 ABC
2020 Period 02 Wk08 202008 ABC
2020 Period 03 Wk09 202009 ABC
2020 Period 03 Wk10 202010 ABC
2020 Period 03 Wk11 202011 ABC
2020 Period 03 Wk12 202012 ABC
2020 Period 03 Wk13 202013 ABC
2020 Period 04 Wk14 202014 ABC
2020 Period 04 Wk15 202015 ABC
Expected output
Year Period Week Week ID Site
2020 Period 01 Wk01 202001 ABC
2020 Period 01 Wk02 202002 ABC
2020 Period 01 Wk03 202003 ABC
2020 Period 01 Wk04 202004 ABC
2020 Period 01 Wk05 202005 ABC
2020 Period 02 Wk06 202006 ABC
2020 Period 02 Wk07 202007 ABC
2020 Period 02 Wk08 202008 ABC
2020 Period 02 Wk09 202009 ABC
2020 Period 03 Wk10 202010 ABC
2020 Period 03 Wk11 202011 ABC
2020 Period 03 Wk12 202012 ABC
2020 Period 03 Wk13 202013 ABC
2020 Period 04 Wk14 202014 ABC
2020 Period 04 Wk15 202015 ABC