我有一个数据框,其中包含一些人员进出某个区域的数据,我想计算出离开的时间戳和进入的时间戳之间的区别。
这是一组,我想填写公式列。在in_out列中,0表示出口,1表示回车。
subject_code in_out timestamp sensor_id sensor_name zone_code zone_name zone_m2 idx union formula time
Ident1 0 2019-02-04 15:00:00 cam08 cam08 MI Ctr Pol OUT MI_CTR_POL MI 32 51103 50498 NaN 2019-02-04 15:00:08
2019-02-04 18:31:00 cam08 cam08 MI Ctr Pol OUT MI_CTR_POL MI 32 52844 50753 NaN 2019-02-04 18:31:58
2019-02-04 20:43:00 cam08 cam08 MI Ctr Pol OUT MI_CTR_POL MI 32 53417 50826 NaN 2019-02-04 20:43:39
2019-02-05 01:29:00 cam08 cam08 MI Ctr Pol OUT MI_CTR_POL MI 32 56223 51087 NaN 2019-02-05 01:29:35
1 2019-02-04 13:47:00 cam07 cam07 MI Ctr Pol IN MI_CTR_POL MIc 32 50498 51103 NaN 2019-02-04 13:47:33
2019-02-04 13:58:00 cam07 cam07 MI Ctr Pol IN MI_CTR_POL MIc 32 50753 52844 NaN 2019-02-04 13:58:45
2019-02-04 14:34:00 cam07 cam07 MI Ctr Pol IN MI_CTR_POL MIc 32 50826 53417 NaN 2019-02-04 14:34:26
2019-02-04 14:52:00 cam07 cam07 MI Ctr Pol IN MI_CTR_POL MIc 32 51087 56223 NaN 2019-02-04 14:52:25
例如,第一种情况是
公式= 2019-02-04 15:00:00-2019-02-04 13:47:00
编辑:我使用df.groupby(['subject_code', 'in_out', pd.Grouper(key='timestamp', freq='60s')]).first()