2 回答
TA贡献1803条经验 获得超6个赞
尝试使用pd.to_datetime和pd.to_timedelta:
df['Starttime'] = pd.to_datetime(df['Date'].map(str) + ' ' + df['Time'].map(str))
df['Endtime'] = df['Starttime'] + pd.to_timedelta(df['TimeDelta'])
TA贡献1876条经验 获得超5个赞
首先将dates 和times 转换为字符串Series.astype,然后使用to_datetime,第二列使用to_timedelta:
df = pd.DataFrame({'Date': pd.to_datetime(['06.12.2019','06.12.2019']).date,
'Time': pd.to_datetime(['17:20:10','17:20:31']).time,
'TimeDelta':['00:00:21','14:31:09']})
df['Starttime'] = pd.to_datetime(df['Date'].astype(str) + ' ' + df['Time'].astype(str))
df['Endtime'] = df['Starttime'] + pd.to_timedelta(df['TimeDelta'])
print (df)
Date Time TimeDelta Starttime Endtime
0 2019-06-12 17:20:10 00:00:21 2019-06-12 17:20:10 2019-06-12 17:20:31
1 2019-06-12 17:20:31 14:31:09 2019-06-12 17:20:31 2019-06-13 07:51:40
添加回答
举报