August 2019
Beginner
482 pages
12h 56m
English
A separate form of aggregation is time-based resampling. You can think of this practice as grouping by time period—except that statistics will be filled for missed time periods, too.
For example, let's count casualties for each month of the war, assuming the end of each battle as a time point. For that, we'll have to set DateTime as an index, first. For the sake of simplicity, let's create a copy of the dataframe to perform on:
ts = data[['axis killed', 'allies killed', 'end']].copy()ts = ts.set_index('end').sort_index()
Now, all we need to do is define the frequency and aggregation method, and we're good to go:
>>> timeline = ts.resample('1Y').agg('sum')>>> timeline axis killed allies killedend 1939-12-31 23727.0 166092.01940-12-31 ...