我想算的次数每id, date的datetime是10秒钟前一行不同。数据id timestamp datetime date 1 1496660340 2019-06-05 10:59:00 2019-06-051 1496660340 2019-06-05 10:59:10 2019-06-05 1 1496660355 2019-06-05 10:59:40 2019-06-05 <- 30 sec diff from above, so not counted1 1496655555 2019-06-06 11:58:00 2019-06-06 1 1496666666 2019-06-06 11:58:10 2019-06-06 1 1496666677 2019-06-06 11:58:20 2019-06-06 2 1496655555 2019-06-05 11:58:00 2019-06-05 2 1496666666 2019-06-05 11:58:10 2019-06-05 2 1496666677 2019-06-05 11:58:20 2019-06-05 Data columns (total 4 columns): id int64 timestamp int64 datetime datetime64[ns] date object想要的id date num_count1 2019-06-05 11 2019-06-06 22 2019-06-05 2我试过的# get all the time differences firstdf['timediff'] = df.groupby(['id','date'])['datetime'].diff() / np.timedelta64(1, 's')#Count the number of 10sec differencesx = pd.DataFrame(df[df['timediff']==10].groupby(['id','date'],as_index=False)['timediff'].count())我不确定这是否是正确的方法。有人可以指出我正确的方向吗?
添加回答
举报
0/150
提交
取消