Window calculations

All the functions and methods we have used so far have involved the full row or column; however, sometimes, we are more interested in the values over a certain window or range of rows/columns. When we have a DatetimeIndex, we can specify the windows in day parts (such as 2H for two hours or 3D for three days), otherwise we can specify the number of periods as an integer. Say we are interested in the amount of rain that has fallen in a rolling three-day window; it would be quite tedious (and probably inefficient) to implement this with what we have learned so far. Fortunately, we can use the rolling() method on dataframes to get this information easily:

>>> central_park_weather['2018-10'].assign(... rolling_PRCP=lambda ...

Get Hands-On Data Analysis with Pandas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.