使用python pandas找到'Time Delayed'

时间:2013-07-26 19:21:57

标签: python pandas

我有以下数据框;

Group     Deadline Time    Deadline Date    Task Completed Date   Task Completed Time
Group 1   20:00:00         17-07-2012       17-07-2012              20:34:00
Group 2   20:15:00         17-07-2012       17-07-2012              20:39:00
Group 3   22:00:00         17-07-2012       17-07-2012              22:21:00
Group 4   23:50:00         17-07-2012       18-07-2012              00:09:00
Group 5   20:00:00         18-07-2012       18-07-2012              20:37:00
Group 6   20:15:00         18-07-2012       18-07-2012              21:13:00
Group 7   22:00:00         18-07-2012       18-07-2012              22:56:00
Group 8   23:50:00         18-07-2012       19-07-2012              00:01:00
Group 9   20:15:00         19-07-2012       19-07-2012              20:34:00
Group 10  20:00:00         19-07-2012       19-07-2012              20:24:00

如何计算时间延迟;

Time Delay (mins)
00:34:00
00:24:00
00:21:00
00:19:00
00:37:00
00:58:00
00:56:00
00:11:00
00:19:00
00:24:00

我尝试过没有成功;

  1. 结合'截止日期''日期'& '时间'列和'任务已完成''日期'& '时间'列和

  2. 将差异视为“任务已完成” - “截止日期”时间。

1 个答案:

答案 0 :(得分:3)

将它们组合为字符串(“添加”工作),将它们转换为datetime类型,然后减去,这会得到一系列timedelta类型。

In [14]: deadline = pd.to_datetime(df['Deadline Date'] + ' ' + df['Deadline Time'])

In [15]: completed = pd.to_datetime(df['Task Completed Date'] + ' ' + df['Task Completed Time'])

In [16]: completed - deadline
Out[16]: 
0   00:34:00
1   00:24:00
2   00:21:00
3   00:19:00
4   00:37:00
5   00:58:00
6   00:56:00
7   00:11:00
8   00:19:00
9   00:24:00
dtype: timedelta64[ns]