how do you create timestamp columns from combine str timedeltadatetime columns?

Including info from your other question, given a df like

df
          date      hour  duration[min]
0  2019-08-11  13:50:00             10
1  2019-08-11  15:00:00             30
2  2019-08-11  16:30:00              5
3  2019-08-11  18:00:00             15

you can simply calculate start and end timestamps like

df['interview_start'] = pd.to_datetime(df['date']+' '+df['hour'])
df['interview_end'] = df['interview_start'] + pd.to_timedelta(df['duration[min]'], unit='min')

# df
#          date      hour  duration[min]     interview_start       interview_end
# 0  2019-08-11  13:50:00             10 2019-08-11 13:50:00 2019-08-11 14:00:00
# 1  2019-08-11  15:00:00             30 2019-08-11 15:00:00 2019-08-11 15:30:00
# 2  2019-08-11  16:30:00              5 2019-08-11 16:30:00 2019-08-11 16:35:00
# 3  2019-08-11  18:00:00             15 2019-08-11 18:00:00 2019-08-11 18:15:00

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top