Reimplement pandas' Series.rolling(window, min_periods).mean() in NumPy, including its handling of missing data:
i - window + 1 to i.NaN values inside the window are ignored.min_periods non-missing values are in the window, the result is NaN. min_periods defaults to window.Implement rolling_mean(values, window, min_periods=None) in O(n) using cumulative sums of the values (with NaNs as 0) and of a valid-value mask. Then implement expanding_mean(values, min_periods=1), the mean of all non-missing values so far.