Resampling
Back in Chapter 8, Group By, we went in-depth into the group by functionality that pandas has to offer. A Group By allows you to split your data based on unique value combinations in your dataset, apply an algorithm to those splits, and combine the results back together.
A resample is very similar to a Group By, with the only difference happening during the split phase. Instead of generating groups from unique value combinations, a resample lets you take datetimes and group them into increments like every 5 seconds or every 10 minutes.
How to do it
Let’s once again reach for the pd.date_range function we were introduced to back in the Datetime selection recipe, but this time, we are going to generate a pd.DatetimeIndex with a frequency of seconds instead of days:
index = pd.date_range(start="2024-01-01", periods=10, freq="s")
ser = pd.Series(range(10), index=index, dtype=pd.Int64Dtype())
ser
2024-01-01 00:00:00 0
2024-01...