I am trying to create a new column based on a timestamp column in Python using pandas and datetime libraries.
I have tried using datetime, as other methods I have tried have not given the results closest to what I want. It seems so simple but I cant figure it out.
This is the closest I have gotten to what I want so far:
import datetime as dt
datetime.datetime.now().minute
datetime.datetime.now().hour
minute1 = dfclean['Time Call Was Received'].dt.minute
minute2 = dfclean['Time Vehicle was Dispatched'].dt.minute
minute3 = dfclean['Time Vehicle was en Route to Scene'].dt.minute
minute4 = dfclean['Time Arrived on Scene'].dt.minute
minute5 = dfclean['Time Arrived at Patient'].dt.minute
minute6 = dfclean['Time Departed from the Scene'].dt.minute
minute7 = dfclean['Time Arrived at Hospital'].dt.minute
dfclean['Mins Call Received to Vehicle Dispatched'] = minute2 - minute1
dfclean['Mins Vehicle En Route to Arrival On Scene'] = minute4 - minute3
dfclean['Mins Vehicle Arrived at Patient to Departing From Scene'] = minute6 - minute5
dfclean['Mins Departing Scene to Arriving at Hospital'] = minute7 - minute6
Here is the output I am talking about
However, this returns negative values since it is only extracting the minutes. So if the timestamp is subtracting 9:00 am from 8:51am I get -49. Is there a way to include hours in the subtraction so it doesnt account for the negative number? Or maybe a completely different approach that is easier?
Any help is greatly appreciated!
I want the output to be exact minutes, single number.