Your question is Moving Average With Missing Values. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Avenue Code's ML pipelines may receive time-series measurements with missing samples. Given an ordered sequence of numeric values, compute the trailing moving average for every position while ignoring missing values.
Use None to represent a missing sample. For each index, consider the current value and up to window - 1 preceding values. Average only the non-missing values in that window. If every value in a window is missing, return None for that position.
Implement moving_average(values, window), where values is a list containing integers, floating-point numbers, or None, and window is a positive integer. Return a list of the same length containing floating-point averages or None.
def moving_average(values, window):