'calculating duration between two time columns
I have entry and exit time and I want to derive the total duration in seconds . I first converted it into date time and then made separate columns for entry and exit time using this code
import datetime as dt
from datetime import datetime
df["Entry Date Time"] = pd.to_datetime(df["Entry Date Time"])
df["Exit"] = pd.to_datetime(df["Exit"])
df["EXIT_TIME"] = df["Exit"].apply(lambda x : x.time())
df["ENTRY_TIME"] = df["Entry Date Time"].apply(lambda x : x.time())
Now I want to know the duration I tried doing this:
df["diff"] = df["EXIT_TIME"] - df["ENTRY_TIME"]
but it raises the error:
"unsupported operand type(s) for -: 'datetime.time' and 'datetime.time'"
How do I calculate the total duration for each row?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|