06
How would you compute a 7-day moving average in Python?
Tap to write answer
0 words | 0 charsPress Enter ↵ to reveal
Your Attempt
0 wordsRefined Model Answer
ReferenceI would use a rolling window over the numeric column and then take the mean. In Pandas, that is usually a rolling(7).mean() pattern, with attention to the first few rows where a full window is not available. The reason I choose this approach is that it is clear, efficient, and easy to verify. I would also think about whether the data needs to be sorted by time before computing the window. If the interviewer wants more detail, I would mention how I would handle missing values or irregular intervals.