I have calculated monthly rolling average for my data but there is a one-month lag (delay) in calculation such that if we are in October, the results need to deliver the September monthly average and so on for the rest of the year for each month. What argument can I add to my rolling average to take into account that lag?
history_data_resampled.rolling(window = 12).mean()
There are multiple ways you can achieve this. I'll assume
history_data_resampledhas a day frequency, and that you're usingpandas:In the above example, we've resampled the data to a monthly frequency, summing all values from the same month, and then for each month, calculated the average of the previous 12 months. We're using
.resample("1M")['value'].sum()to sum all observations that fall in a specific month together.Note that before
'2021-11'we couldn't calculate any value, since our data would require us to have values from'2020'in our dataset.