I have a dataframe that looks like this:
Date Name Provider Task StartDateTime LastDateTime
2020-01-01 00:00:00 Bob PEM ED A 7a-4p 2020-01-01 07:00:00 2020-01-01 16:00:00
2020-01-02 00:00:00 Tom PEM ED C 10p-2a 2020-01-02 22:00:00 2020-01-03 02:00:00
I would like to list the number of hours between each person's StartDateTime
LastDateTime
(datetime64[ns]) and then create an updated dataframe to reflect said lists. So for example, the updated dataframe would look like this:
Name Date Hour
Bob 2020-01-01 7
Bob 2020-01-01 8
Bob 2020-01-01 9
...
Tom 2020-01-02 22
Tom 2020-01-02 23
Tom 2020-01-03 0
Tom 2020-01-03 1
...
I honestly do not have a solid idea where to start, I've found some articles that may provide a foundation but I'm not sure how to adapt my query to the below code since I want the counts based on the row and hour values.
def daterange(date1, date2):
for n in range(int ((date2 - date1).days)+1):
yield date1 + timedelta(n)
start_dt = date(2015, 12, 20)
end_dt = date(2016, 1, 11)
for dt in daterange(start_dt, end_dt):
print(dt.strftime("%Y-%m-%d"))
https://www.w3resource.com/python-exercises/date-time-exercise/python-date-time-exercise-50.php