如何计算按相同特定属性分组的两个纸卷中两个单元格之间的日期时间差?

时间:2019-05-01 17:29:56

标签: python for-loop rows

我有一个包含主题,时间和时间的数据集。我想计算出每个外出时间与下一个进入时间之间的特定主题的时间(例如重新录取时间)。对于每个主题,它可能都有几次不同的访问。那我怎么计算呢?

ipl_data = {'Subject': ['Riders', 'Riders', 'Devils', 'Devils', 'Kings',
   'Kings', 'Kings', 'Kings', 'Royals', 'Royals', 'Royals'],
   'In_time': ['2152-09-03 07:15:00', "2156-10-18 19:34:00",'2185-07-18 16:46:00','2190-02-23 05:23:00','2131-04-30 07:15:00',\
               '2131-05-12 19:49:00' ,'2134-05-10 11:30:00','2196-12-06 07:13:00','2198-08-02 04:49:00','2198-11-01 22:36:00',\
              '2199-10-20 12:05:00'],
   'Out_time': ['2152-09-08 19:10:00','2156-10-25 14:00:00','2185-07-20 16:00:00','2190-02-25 20:20:00','2131-05-08 14:00:00',\
                '2131-05-25 13:30:00','2134-05-20 13:16:00','2197-01-03 14:00:00','2198-10-26 14:55:00','2198-11-14 14:20:00',\
               '2199-10-23 17:30:00']}
df = pd.DataFrame(ipl_data)
df

enter image description here

预期结果: 两次访问之间的时间:车手:30天,恶魔:60天,国王:10天,20天,30天,皇家:40天,50天...

0 个答案:

没有答案