I have a dataframe of the ending time and the next starting time for various car rides. These columns represent how long the given car was parked at its parking spot before being driven again. My goal is to create new column(s) in the dataframe that include each hour of the day in which that car was parked. Example of the dataframe is as such:
End Time Next start time
0 2018-01-02 11:23:54.591 2018-01-03 08:22:06.408
1 2018-01-03 08:51:57.027 2018-01-04 15:07:54.105
2 2018-01-05 01:08:00.000 2018-01-05 17:58:43.829
3 2018-01-05 18:10:20.337 2018-01-05 19:02:00.906
4 2018-01-05 19:12:06.385 2018-01-05 19:41:21.319
I have already run code to find the difference in the two columns in hours:
df['time_parked'] = df['Next start time'] - df['End Time']
df['time_parked'] = df['time_parked'] / np.timedelta(1, 'h')
The question now is how do I calculate which day of the week and hour of the day these cars were parked? The ideal end output would be new columns for each day of the week, and another set of columns ranging from 0-23 representing the hour of the day, and for each observation a 0 or 1 in the day of the week column and hour of the day columns representing if that car was parked at that given time or not. Does anyone know the best way to do this in python?