Reputation: 173
I have dataframe that look like this.
| Date_Time | Execution_Time |
|---------------------|----------------|
| 2019-10-10 09:07:29 | 14.0 |
| 2019-09-21 19:47:01 | 14.3 |
| 2019-09-19 02:49:49 | 14.1 |
| 2019-09-27 23:19:16 | 21.9 |
| 2019-09-05 18:46:00 | 14.2 |
The execution is in seconds. How can I add Date_Time
and Execution_Time
?
datatype for Date_Time: object
,
Execution_Time: float64
I have tried df['diff'] = df['Date_Time'] + df['Execution_Time']
and it returns following error:
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')
Upvotes: 2
Views: 349
Reputation: 862511
First column convert to datetimes by to_datetime
and second to timedeltas by
to_timedelta
:
df['diff'] = (pd.to_datetime(df['Date_Time']) +
pd.to_timedelta(df['Execution_Time'], unit='s'))
print (df)
Date_Time Execution_Time diff
0 2019-10-10 09:07:29 14.0 2019-10-10 09:07:43.000
1 2019-09-21 19:47:01 14.3 2019-09-21 19:47:15.300
2 2019-09-19 02:49:49 14.1 2019-09-19 02:50:03.100
3 2019-09-27 23:19:16 21.9 2019-09-27 23:19:37.900
4 2019-09-05 18:46:00 14.2 2019-09-05 18:46:14.200
Upvotes: 4