我有这个数据框:对于每个 IMEI,我想检查是否有后续DATETIME OF LVD发生在 12 小时内。如果有,则需要将其移除。例如,在此 df 行中,需要删除 1、6、13、14、15 行。 IMEI DATETIME OF LVD 0 864811031001402 2018-10-04 23:50:00 1 864811031001402 2018-10-05 04:35:00 2 864811031001402 2018-10-15 03:40:00 3 864811031001402 2018-10-21 04:25:00 4 866710038341548 2018-10-27 05:53:00 5 864811031092336 2018-10-17 18:10:00 6 864811031092336 2018-10-17 18:41:00 7 864811031092336 2018-10-21 04:50:00 8 864811031092336 2018-10-23 03:21:00 9 864811031092336 2018-10-24 03:00:00 10 864811031009041 2018-10-13 21:52:00 11 864811031009041 2018-10-27 11:13:00 12 864811031015584 2018-10-27 00:48:00 13 864811031015584 2018-10-28 05:25:00 14 864811031015584 2018-10-28 05:26:00 15 864811031015584 2018-10-28 05:27:00 我可以获得每条记录的 delta 时间差(如下),但我如何为每个 IMEI 组做到这一点?df['Delta'] = pd.to_datetime(df['DATETIME OF LVD']).diff() IMEI DATETIME OF LVD Delta0 864811031001402 2018-10-04 23:50:00 NaT1 864811031001402 2018-10-05 04:35:00 0 days 04:45:002 864811031001402 2018-10-15 03:40:00 9 days 23:05:003 864811031001402 2018-10-21 04:25:00 6 days 00:45:004 866710038341548 2018-10-27 05:53:00 6 days 01:28:005 864811031092336 2018-10-17 18:10:00 -10 days +12:17:006 864811031092336 2018-10-17 18:41:00 0 days 00:31:00
添加回答
举报
0/150
提交
取消