I have a list of timestamps of when an event A happens, and I want to figure out if there are certain time (within the hour) when A happens.
Here is a list of times when the event happens. I formatted a new line to signify a new day. From the list we can see that the event will likely happen between 7:50 am and 8:50 am every day. The output here should be about an hour range, and since 7:50 - 8:50 is the time range that contains the most amount of events, that should be the answer.How can I figure that pattern out using Python?
I tried rounding to the nearest hour and then finding the most common time, but that gave me 7 am - 8 am instead of 7:50 am - 8:50 am. For this problem, I'm assuming event A will happen every day.
Expected answer: 7:50 - 8:50
Why? Calculating the number of timestamps one hour ranges can cover:
- 8:30 - 9:30: 2
- 14:40 - 15: 40: 1
- 20:40 - 21:40: 1
- 8:40 - 9:40: 1
- 20:00 - 21:00 : 2
- 8:40 - 9:40: 1
- 8:20 - 9:20: 3
- 7:50 - 8:50: 4
import datetime
times = [datetime.time(8, 30), datetime.time(14, 40), datetime.time(20, 40),
datetime.time(8, 40), datetime.time(20, 00),
datetime.time(8, 20),
datetime.time(7, 50)]