For ser.rolling(window=3).mean() on a series longer than three values, what appears in the first two positions?
Correct answer
B. NaN, because min_periods defaults to the window size
16 views
B. NaN, because min_periods defaults to the window size
16 views
Rolling windows: min_periods defaults to the window length, so positions without a full window yield NaN, and setting min_periods=1 gives partial-window means instead. expanding() is the cumulative alternative and ewm() applies exponential weighting. Always inspect the first and last rows, because windowing changes which output positions carry valid values.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.