我在DNS记录中定位信标活动,并且我的pandas数据框包含已解析的DNS记录。
结构如下:
Received_Time Sender_IP Receiver_IP Content
2019-01-01 23:59:54.999 0.0.0.1 1.1.1.1 ...
2019-01-01 23:59:56.999 0.0.0.1 1.1.1.1 ...
2019-01-01 23:59:57.999 0.0.0.1 1.1.1.1 ...
2019-01-01 23:59:58.999 0.0.0.1 1.1.1.1 ...
2019-01-01 23:59:59.999 0.0.0.1 1.1.1.2 ...
我正在努力实现:
Beacon_Interval(s) Beacon_Count(including first) Sender_IP Receiver_IP
1.000 3 0.0.0.1 1.1.1.1
时间是日期时间类型,我的想法是:
我不确定如何进行第一步。我还要发帖看看是否有人有更好的方法来完成任务,在此先感谢您。
根据我的理解,您想获得每个“接收时间”的间隔,这可以通过以下方式完成:
df['Beacon_Interval(s)'] = df['Received_Time'].diff().dt.seconds
由于我们现在知道了“信标间隔”,因此我们可以使用以下代码计算其实例数:
#Note, since you explicitly tell that it should count the first instance, I used +2 instead of +1 in the end.
df['Beacon_Count(including first)'] = \
df.groupby((df['Beacon_Interval(s)'] != df['Beacon_Interval(s)'].shift(1)).cumsum()).cumcount()+2
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句