Идея состоит в том, чтобы создать datetime
столбец to_datetime
и timedeltas to_timedelta
и столбцы суммы:
df['time_start'] = pd.to_timedelta(df['time_start'])
df['time_end'] = pd.to_timedelta(df['duration_seconds'], unit='s') + df['time_start']
df['date'] = pd.to_datetime(df['date'], format='%d-%m-%y')
df['time_start_with_date'] = df['date'] + df['time_start']
df['time_end_with_date'] = df['date'] + df['time_end']
print (df)
date time_start duration_seconds time_end \
0 2018-01-10 12:56:52 1382 0 days 13:19:54
1 2018-01-10 12:56:52 164 0 days 12:59:36
2 2018-01-10 23:56:00 250 1 days 00:00:10
time_start_with_date time_end_with_date
0 2018-01-10 12:56:52 2018-01-10 13:19:54
1 2018-01-10 12:56:52 2018-01-10 12:59:36
2 2018-01-10 23:56:00 2018-01-11 00:00:10
Для пользовательского формата datetimes:
df['time_start'] = pd.to_timedelta(df['time_start'])
df['time_end'] = pd.to_timedelta(df['duration_seconds'], unit='s') + df['time_start']
date = pd.to_datetime(df['date'], format='%d-%m-%y')
df['time_start_with_date'] = (date + df['time_start']).dt.strftime('%d-%m-%y %H:%M:%S')
df['time_end_with_date'] = (date + df['time_end']).dt.strftime('%d-%m-%y %H:%M:%S')
#https://stackoverflow.com/a/51102096/2901002
#solution convert only HH:MM:SS to strings, removed all days
df['time_start'] = df['time_start'].astype(str).astype(str).str[-18:-10]
df['time_end'] = df['time_end'].astype(str).astype(str).str[-18:-10]
print (df)
date time_start duration_seconds time_end time_start_with_date \
0 10-01-18 12:56:52 1382 13:19:54 10-01-18 12:56:52
1 10-01-18 12:56:52 164 12:59:36 10-01-18 12:56:52
2 10-01-18 23:56:00 250 00:00:10 10-01-18 23:56:00
time_end_with_date
0 10-01-18 13:19:54
1 10-01-18 12:59:36
2 11-01-18 00:00:10