0

I have a data frame with two columns representing the departure and arrival times of an aircraft. Each element in these columns is datetime.time object. Each column e.g. df['CRS_ARR_TIME'] is series and looks as follows:

0         15:10:00
1         16:15:00
2         15:12:00
3         15:18:00
4         17:30:00
...

I cannot find the duration of the flight since whenever subtracting the two columns I get an error. I also tried to use to_timedelta:

df_subset[['CRS_ARR_TIME','CRS_DEP_TIME']] = df_subset[['CRS_ARR_TIME','CRS_DEP_TIME']].apply(pd.to_timedelta)

but it does not work because I get:

Invalid type for timedelta scalar: <class 'datetime.time'>

Would be thankful for any suggestions.

Anna
  • 1
  • 2
  • Are the times always in the same day? Have you tried this solution - https://stackoverflow.com/questions/5259882/subtract-two-times-in-python ? – Tom McLean Apr 13 '21 at 16:20
  • Related: [TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.time'](https://stackoverflow.com/questions/31156031/typeerror-unsupported-operand-types-for-datetime-time-and-datetime-time). – wwii Apr 13 '21 at 16:24
  • @TomMcLean yes, I tried it. It works elementwise but not columnwise. – Anna Apr 13 '21 at 16:25

0 Answers0