How To Ignore Nan In Rolling Average Calculation In Python
For a time series sales forecasting task I want to create a feature that represents the average sales over the last 3 days. I have a problem when I want to predict the sales for da
Solution 1:
Here is on way adding min_periods
s=df.Sales.rolling(window=2,min_periods=1).mean()
s.iloc[0]=np.nan
s
Out[1293]:
0 NaN
1 150.0
2 250.0
3 250.0
4 200.0
Name: Sales, dtype: float64
Post a Comment for "How To Ignore Nan In Rolling Average Calculation In Python"