I am trying to create a session template of dates for a dataframe in pandas based on the start and end day of the week of my given dataframe. I have the start and end day abbreviations (Mo, Tu, We, etc.) and the start/end time (8:30 AM, 5:30 PM, etc.).
What I want to create is a template that gives the start day abbreviation, the times over the days that it spans, and the end day. For example, my dataframe currently looks like the following:
Start Time End Time Start/End Namestart Nameend Days Session Template
Mo 8:30 AM Th 5:30 PM Mo 8:30 AM-Th 5:30 PM Mo Th 4 Day 4 Day Mo 8:30 AM-Th 5:30 PM
We 8:30 AM Fr 12:30 PM We 8:30 AM-Fr 12:30 PM We Fr 3 Day 3 Day We 8:30 AM-Fr 12:30 PM
The current session template gives me the day count, start time, end time, and the day of week it begins/ends on. However, I would like for it to give each individual day that the item spans. For the examples above it should yield:
4 Day Mo 8:30 AM-5:30 PM, Tu 8:30 AM-5:30 PM, We 8:30 AM-5:30 PM, Th 8:30 AM-5:30 PM.
3 Day We 8:30 AM-5:30 PM, Th 8:30 AM-5:30 PM, Fr 8:30 AM-12:30 PM
Start_timeandEnd_time. So only use times in those columns and you already have theNamestartandNameend. You can then loop over the days fromNamestarttoNameendand for each day, print theStart_timeandEnd_time.8:30 AMand5:30 PM. You will essentially reach a similar step as above but without modifying the data frame. It can be done elegantly usingregex(regular expressions).listlikedays = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']and increment a counter after you print for one day. Another way would be to store adictionaryof (day, index) pairs, like sodays = {'Mo':1, 'Tu':2, 'We':3, 'Th':4, 'Fr':5, 'Sa':6, 'Su':7]and then you can just use the difference between the corresponding indices. So betweenTuandFr, you have5-2+1=4days. You will need to take care of the edge cases.