python 如何计算时间间隔之间的特定行数

gstyhher  于 2022-11-27  发布在  Python
关注(0)|答案(1)|浏览(121)

我有一个包含两列的数据集:时间和源,我想计算192.168.1.128每一秒之间的www.example.com

I have this:

                 Time           Source
  2022-11-27 09:19:27    192.168.1.128
  2022-11-27 09:19:27    152.199.19.161
  2022-11-27 09:19:27    192.168.1.128
  2022-11-27 09:19:27    192.168.1.128
  2022-11-27 09:19:28    142.250.186.67
  2022-11-27 09:19:29    192.168.1.128
  2022-11-27 09:19:29    192.168.1.128
  2022-11-27 09:19:30    192.168.1.128
  2022-11-27 09:19:30    142.250.186.67

and trying to get it like this:

                 Time       Count 
  2022-11-27 09:19:27           3
  2022-11-27 09:19:28           0
  2022-11-27 09:19:29           2
  2022-11-27 09:19:30           1
xqkwcwgp

xqkwcwgp1#

您可以用途:

df['Source'].eq('192.168.1.128').groupby(df['Time']).count().reset_index()

相关问题