Rolling average
A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.
The task
Return the 3-day rolling average of `visits`. The first two days do not have three values yet, so they should be NaN.
What this exercise teaches
Each value is the mean of that day and the two days before it. Until the window is full, rolling returns NaN, unless you lower min_periods.
A hint if you get stuck
rolling(n) builds a moving window of n rows. Follow it with an aggregation such as mean().
This exercise is part of Pro
Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.