I am looking for a special window function in pandas: sort of a combination of rolling and expanding. For calculating (for instance) the mean and standard deviating, I want to regard all past data, but ignore the first few records to make sure I have a multiple of 7 (days in my case). That's because I know the data has a strong weekly pattern.
Example:
s = pd.Series([1, 3, 4, 5, 4, 3, 1, 2, 4, 5, 4, 5, 4, 2, 1, 3, 4, 5, 4, 3, 1, 3],
pd.date_range('2020-01-01', '2020-01-22'))
s.rolling(7, 7).mean() # Use last 7 days.
s.expanding(7).mean() # Use all past days.
s.mywindowing(7).mean() # Use last past multiple of 7 days. How?
The effect should be like this:
Of course I can do things manually using for
loops and such, but I imagine the existing pandas machinery can be used to do this...?
Pandas custom window rolling
another usage here
Outputs: