I have a list of start and end times, my_list
, which contains different groupings of start and end times.
- 8:45 - 11:00
- 9:00 - 11:00
- 9:15 - 11:00
- 9:30 - 11:00
- 12:30 - 15:00
- 12:30 - 15:00
- 12:45 - 15:00
These records are group therapy session start/end times for patients entered by one therapist. I need similar times grouped together so that I can check if there were more than 3 lists in the groupings. So from 9:00 - 11:00, there were 4 patients when the rules only allow 3.
This question's answers provide help for help finding all of the overlapping times in one given list and I've tried variations of the solutions posted there. But I need to find overlapping times based on groups of similar times.
my_list = [
[dt.time(8,45), dt.time(11,0)],
[dt.time(9,0), dt.time(11,0)],
[dt.time(9,15), dt.time(11,0)],
[dt.time(9,30), dt.time(11,0)],
[dt.time(12,30), dt.time(15,0)],
[dt.time(12,30), dt.time(15,0)],
[dt.time(12,45), dt.time(15,0)],
]
I need to group similar/duplicated/overlapping times...
group_one = [
[dt.time(8,45), dt.time(11,0)],
[dt.time(9,0), dt.time(11,0)],
[dt.time(9,15), dt.time(11,0)],
[dt.time(9,30), dt.time(11,0)]
]
group_two = [
[dt.time(12,30), dt.time(15,0)],
[dt.time(12,30), dt.time(15,0)],
[dt.time(12,45), dt.time(15,15)]
]
Eventually, checking len(group_one) > 3
returns True
# Pseudo-code
for times in my_list:
if start or end times are equal to or overlap each other:
throw the times into separate, similar lists (or dicts where key = timeslot?)
else:
if start or end times....
Solution can be pure Python or Pandas as this data is coming from a dataframe and will be manipulated there. I can't help but feel there is a magical way of doing this in Pandas, just stuck!
Edit: changed data in question to match answer.