I have a pandas dataframe where it has start_time, end_time and booking duration.
Please find below example dataframe
| id | Start_time | End_time | Duration |
|---|---|---|---|
| 1 | 2013-11-20 09:00:00 | 2013-11-20 09:30:00 | 0 days 0:30:00 |
| 2 | 2013-11-20 09:00:00 | 2013-11-20 12:10:00 | 0 days 3:10:00 |
| 3 | 2013-11-20 10:00:00 | 2013-11-20 11:00:00 | 0 days 1:00:00 |
| 4 | 2013-11-20 08:00:00 | 2013-11-20 09:40:00 | 0 days 1:40:00 |
I am trying to get the timeslots from the above dataframe
Expected output:
| id | Start_time | End_time | Duration | Timeslots |
|---|---|---|---|---|
| 1 | 2013-11-20 09:00:00 | 2013-11-20 09:30:00 | 0 days 0:30:00 | 9 - 10 |
| 2 | 2013-11-20 09:00:00 | 2013-11-20 12:10:00 | 0 days 3:10:00 | 9-10 |
| 2 | 2013-11-20 09:00:00 | 2013-11-20 12:10:00 | 0 days 3:10:00 | 10-11 |
| 2 | 2013-11-20 09:00:00 | 2013-11-20 12:10:00 | 0 days 3:10:00 | 11-12 |
| 3 | 2013-11-20 10:00:00 | 2013-11-20 11:00:00 | 0 days 1:00:00 | 10 - 11 |
| 4 | 2013-11-20 08:00:00 | 2013-11-20 09:40:00 | 0 days 1:40:00 | 8-9 |
| 4 | 2013-11-20 08:00:00 | 2013-11-20 09:40:00 | 0 days 1:40:00 | 9-10 |
What I have tried till now
I can get the slots from start_time and end_time but i am missing the expected output
| id | Start_time | End_time | Duration | TimeSlot |
|---|---|---|---|---|
| 1 | 2013-11-20 09:00:00 | 2013-11-20 09:30:00 | 0 days 0:30:00 | 9-9:30 |
| 2 | 2013-11-20 09:00:00 | 2013-11-20 12:10:00 | 0 days 3:10:00 | 9-12:10 |
| 3 | 2013-11-20 10:00:00 | 2013-11-20 11:00:00 | 0 days 1:00:00 | 10-11 |
| 4 | 2013-11-20 08:00:00 | 2013-11-20 09:40:00 | 0 days 1:40:00 | 8 - 9:40 |
Can anyone give some hints please
Try:
Setup to be reproducible: