1

I have two columns start_time and execution time, I need to use these two columns and create a new column end_time, which is the sum of my start_time and execution_time:

        start_time        execution_time   end_time
   0    13-05-2013 04:04    00:24:48       13-05-2013 4:28:48
   1    13-05-2013 04:44    00:09:23       13-05-2013 4:53:23
   2    13-05-2013 23:24    00:06:51       13-05-2013 23:30:51
   3    22-05-2013 16:31    00:06:05       22-05-2013 16:37:05
   4    22-05-2013 20:55    00:06:51       22-05-2013 21:01:51

One catch here is if the minute crosses 60 it should be appended to next hour as shown in the last record. and also if the hour crosses 24 it should be appended to the next day.

Please help me in getting the results. Thanks in advance

nivedan gowda
  • 205
  • 2
  • 9

1 Answers1

1

Here are some empty strings or some another bad values in Time column, so is necessary add errors='coerce' to to_timedelta for missing values NaT for this values and replace them by 00:00:00 timedelta for avoid missing values in end_time if add start_time converted to datetimes:

td = pd.to_timedelta(df.execution_time.astype(str), errors='coerce').fillna(pd.Timedelta(0))
df['end_time']= pd.to_datetime(df.start_time) + td
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252