Why this topic?
This topic doesn’t have much documentation, yet is potentially very useful. Calculating moving averages in Excel is time-consuming. Furthermore, when you use a window function in SQL you must structure the query carefully. Why not do it in Pandas instead?
What it covers:
First, I demonstrate how to use .rolling() to get a 7-day moving average of daily new COVID-19 cases. Next, I show how to use 3 other features of the .rolling method:
- Using an offset instead of an integer window
- The “min_periods” keyword argument
- “Closed” keyword argument