I have a list of DB records (i.e. class instances), which include a datetime object as well as a boolean flag. There may be such a record for every few seconds, but there may also be some hours (or even days) without any such record.
Now I want to count the number of these records per hour in which the boolean flag is True. But these buckets should include also those hours where either no record with a True flag is or where no record is at all.
So for example see this list of records:
2021-07-05T00:00:32 --> False
2021-07-05T00:01:32 --> False
2021-07-05T00:01:45 --> True
2021-07-05T00:02:01 --> False
2021-07-05T00:05:12 --> False
2021-07-05T00:05:24 --> True
2021-07-05T00:05:37 --> True
2021-07-05T00:08:11 --> True
2021-07-05T00:09:12 --> False
2021-07-05T00:10:15 --> False
2021-07-05T00:11:23 --> False
So for these first twelve hours of day 2021-07-05 I would need the following buckets:
hour count
00 0
01 1
02 0
03 0
04 0
05 2
06 0
07 0
08 1
09 0
10 0
11 0
I guess I would find some "manual" solution to this problem - but I also have the feeling there is a more elegant, Pythonic solution, with some list magic or something. Or maybe based on the pandas library? I am not very familiar with that one though ...
Thanks in advance for any ideas!