For a given data frame containing the active time interval for each item, I would like to compute the number of active items in total over time (likely resampled).
For example, for the data frame
df = pd.DataFrame({
'item': ['a', 'b', 'c', 'd'],
'active': [
pd.Interval(pd.Timestamp('2021-04-01 00:00:00'), pd.Timestamp('2021-04-05 00:00:05')),
pd.Interval(pd.Timestamp('2021-04-01 00:30:00'), pd.Timestamp('2021-04-01 01:30:00')),
pd.Interval(pd.Timestamp('2021-04-01 01:00:00'), pd.Timestamp('2021-04-02 02:00:00')),
pd.Interval(pd.Timestamp('2021-04-01 01:00:00'), pd.Timestamp('2021-04-01 01:00:05'))]})
on 2021-04-01 00:45:00, there are two active items (a and b), on 2021-04-03 01:00:00 only one (a).
How can I do that?