I have the following dataframe df
on which I want to compute a 4
-window moving average :
2000-01-03 NaN
2000-01-04 NaN
2000-01-05 -5.0
2000-01-06 1.40
2000-01-07 0.47
I want the following output:
2000-01-03 NaN
2000-01-04 NaN
2000-01-05 NaN
2000-01-06 -1.8
2000-01-07 -1.04
With df.rolling(4).mean()
, I get
2000-01-03 NaN
2000-01-04 NaN
2000-01-05 NaN
2000-01-06 NaN
2000-01-07 NaN
By setting the parameter min_periods=1
, I get
2000-01-03 NaN
2000-01-04 NaN
2000-01-05 -5.0
2000-01-06 -1.8
2000-01-07 -1.04
How do I get rid of NaN
s outside my rolling window?
Thanks!