Sample code:
months = [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sept, Oct, Nov, Dec]
months = pd.period_range(start='2020-01', periods=12, freq='M')
for start, end in zip(months, months[11:]):
end_q = end.qyear
print(start, end, end_q)
# Output:
2020-01 2020-12 2020
This code returns a window with 12 months (start, end) and the last quarter of the window (end_q).
My question is, how can I measure the percentage of the end_q over the full window (start, end)?
I know how to measure the days of the first month in the window with:
first_month = start.month
# number of days in first month (e.g., Jan)
first_month_days = start.days_in_month
Now I am wondering how I could measure the last three months of the window, any suggestion is welcome! Thanks!
EDIT
Example outcome (note I am assuming that each month is composed by 30 days for simplicity):
- If window size is 12 months (360 days) and the last quarter (Oct, Nov, Dec) is composed by 90 days, the outcome should be: 90 / 360 = 0.25
- If windows size is 15 months (450) and last quarter (in the window size) now will be Jan, Feb, Mar (of the next year), the outcome should be: 90 / 450 = 0.2