1. Home
  2. Data Science
  3. Pandas
  4. For ser.rolling(window=3).mean() on a series longer than…

Added 30 Nov -0001

For ser.rolling(window=3).mean() on a series longer than three values, what appears in the first two positions?

  1. An error, because the series is shorter than the window
  2. NaN, because min_periods defaults to the window size Correct answer
  3. The mean of the available values, because partial windows are used
  4. Zero, because missing window values are treated as zero

Correct answer

B. NaN, because min_periods defaults to the window size

16 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs