My dataframe df stores data of times during which machines were working, for example
start_time end_time machine
2019-01-01 00:00:03 2019-01-01 17:10:03 A
2019-01-01 00:31:03 2019-01-01 18:11:03 B
2019-01-01 12:00:00 2019-01-01 13:08:03 C
I want to see how many machines are working simultaneously at any 30 min time window, that is
time_window_start machine_count
2019-01-01 00:00:00 1
2019-01-01 00:30:00 2
... ...
2019-01-01 12:00:00 3
... ...
2019-01-01 13:30:00 2
I started by creating a data frame with time references:
ref_date_range = pd.date_range(start='31/1/2018 00:00:00', end='1/1/2020 23:30:00', freq='30Min')
ref_df = pd.DataFrame(np.random.randint(1, 20, (ref_date_range.shape[0], 1)))
ref_df.index = ref_date_range
But how do I match both data frames including a distinct count of the machines?