Is it possible to include the start and end index values in when using the rolling
function in pandas
such that the values of the series are periodic?
For example, I have the following Series
instance:
import pandas as pd
timestamps = [1, 2, 3, 4]
quantities = [1, 16, 9, 4]
series = pd.Series(quantities, index=timestamps)
which when I type:
series.rolling(window=3, min_periods=3, center=True).median()
yields:
1 NaN
2 9.0
3 9.0
4 NaN
dtype: float64
However, I'd like to include either ends of the series in the calculation such that the result is:
1 median([4, 1, 16]) 4.0
2 median([1, 16, 9]) 9.0
3 median([16, 9, 4]) 9.0
4 median([9, 4, 1]) 4.0
dtype: float64
Thanks for any help trying to achieve this!