这是以毫秒分辨率为单位的数据时间戳和当时接收的数据字节。我想计算接收的字节数/秒
示例:在以下数据中,在09:56:07
收到2个字节 09:56:07:457 - > 7D
09:56:07:841 - > 91
我想通过将时间(以秒为单位)绘制为x轴和字节数为Y轴来显示此数据。
Time ( Hr: Min : Sec: ms) Data ( Packet)
09:56:07:457 -> 7d
09:56:07:841 -> 91
09:56:09:008 -> 02
09:56:09:233 -> 80
09:56:09:345 -> 01
09:56:10:097 -> 80
09:56:10:448 -> 91
09:56:11:424 -> 01
09:56:11:552 -> 01
09:56:12:351 -> 01
09:56:12:607 -> 01
09:56:12:719 -> 01
09:56:13:711 -> 91
09:56:14:574 -> a3
09:56:14:766 -> 02
09:56:15:629 -> 91
09:56:15:773 -> 01
09:56:16:733 -> 91
09:56:16:877 -> 01
09:56:17:805 -> a1
09:58:28:921 -> 02
09:59:00:717 -> 52
09:59:52:459 -> 52
10:17:44:323 -> 01
10:17:44:467 -> 01
10:17:45:875 -> 91
10:17:46:018 -> 03
10:17:46:834 -> 81
10:17:47:010 -> 01
10:17:47:937 -> 92
10:17:48:738 -> 7d
10:17:48:962 -> c9
10:17:49:825 -> 92
10:17:50:097 -> fb
10:17:51:057 -> 8a
10:17:51:952 -> 12
10:17:52:224 -> 01
10:17:53:936 -> 92
10:17:54:272 -> b6
10:22:21:282 -> 3a
10:24:14:347 -> 01
10:24:15:643 -> 01
10:24:15:787 -> 01
10:24:16:010 -> 01
10:24:16:698 -> 01
10:24:16:810 -> 01
10:24:17:769 -> 91
10:24:18:874 -> 7d
10:24:19:689 -> 91
10:24:19:833 -> 01
10:24:19:945 -> 01
10:24:20:793 -> 88
10:24:21:752 -> 91
10:24:21:992 -> 91
10:24:22:760 -> 01
10:24:23:015 -> 05
10:24:24:072 -> 91
10:25:24:451 -> 13
10:25:25:442 -> 92
10:25:27:233 -> 01
10:25:28:384 -> 11
10:25:29:409 -> 02
10:26:02:484 -> 81
10:26:02:724 -> 80
10:26:04:132 -> 96
10:26:05:268 -> 68
10:26:06:084 -> 81
10:26:07:012 -> c8
10:26:07:331 -> a3
10:26:08:018 -> 7d
10:26:08:162 -> 01
10:26:08:979 -> 91
10:26:09:107 -> 01
10:26:09:954 -> fe
10:26:10:994 -> be
10:26:11:074 -> 01
10:26:11:186 -> 01
10:26:12:033 -> 01
10:26:12:273 -> 00
10:26:13:089 -> 12
10:26:13:201 -> 01
10:26:14:017 -> 01
10:26:14:161 -> 01
10:26:15:040 -> 01
10:26:16:048 -> 03
10:26:16:320 -> fc
10:26:17:119 -> 01
10:26:17:375 -> 03
10:26:18:175 -> b1
10:26:18:287 -> 7d
10:26:20:159 -> fa
10:28:58:438 -> ea
10:28:59:559 -> 01
10:29:00:438 -> 3f
10:29:01:398 -> 90
10:29:30:491 -> fd
10:33:15:116 -> 01
10:43:50:509 -> 2a
10:43:52:140 -> 06
10:43:52:284 -> 00
10:44:18:770 -> 00
10:44:18:898 -> 01
10:44:43:562 -> 01
10:45:33:384 -> 0f
10:45:40:134 -> 0f
10:46:22:999 -> 01
10:46:23:302 -> 7d
10:46:54:445 -> 01
10:47:34:030 -> 1f
10:47:53:415 -> 01
10:48:13:248 -> 2f
10:48:47:860 -> 87
10:49:06:334 -> d4
10:49:24:055 -> e5
10:49:36:867 -> b0
10:49:37:075 -> 01
10:49:37:186 -> 01
10:49:57:355 -> 7d
11:00:54:326 -> 64
11:03:42:969 -> a5
11:08:03:741 -> f8
11:08:23:255 -> 2a
11:08:40:385 -> 00
11:08:53:676 -> 01
11:09:14:309 -> f8
11:11:21:320 -> fb
11:16:21:775 -> f9
11:16:21:887 -> dc
11:16:22:111 -> dc
11:16:38:041 -> dc
11:32:46:473 -> b6
11:34:39:089 -> 01
11:34:39:441 -> 92
11:34:40:593 -> 01
11:34:40:737 -> 79
11:34:41:617 -> 40
11:34:41:745 -> 02
11:34:41:872 -> 02
11:34:42:704 -> 00
11:34:42:832 -> 01
11:34:42:976 -> 01
11:34:43:664 -> 01
11:34:43:807 -> 01
11:34:44:031 -> 01
11:34:44:736 -> 01
11:34:45:088 -> 99
11:34:45:919 -> 01
11:34:46:159 -> 01
11:34:46:863 -> 01
11:34:46:991 -> 01
11:34:47:135 -> 01
11:34:47:966 -> 92
11:34:48:206 -> 01
11:34:50:078 -> 92
11:34:51:069 -> fb
11:34:54:203 -> cb
11:35:04:632 -> 01
11:35:06:008 -> d1
11:35:07:095 -> 01
11:35:07:223 -> 00
11:35:07:991 -> 01
11:35:08:311 -> 92
11:35:09:142 -> b4
11:35:09:366 -> 01
11:35:10:151 -> 00
11:35:11:222 -> 02
11:35:11:345 -> 01
11:35:12:213 -> 80
11:35:13:109 -> 01
11:35:13:237 -> 01
11:35:14:101 -> 92
11:35:14:228 -> 00
11:35:29:567 -> 76
11:35:31:071 -> c9
11:35:32:894 -> 20
11:35:32:990 -> 01
11:35:33:134 -> 80
11:35:33:822 -> 01
11:35:34:141 -> c9
11:35:36:030 -> fc
11:35:36:957 -> db
11:35:37:900 -> 7d
11:35:38:044 -> fc
11:35:39:052 -> a0
11:35:40:028 -> 55
11:35:40:220 -> 01
11:35:41:195 -> 01
11:35:42:187 -> 10
11:35:43:114 -> c9
11:36:19:135 -> 90
11:48:45:738 -> 01
11:48:45:962 -> 92
11:48:47:339 -> 92
11:48:47:465 -> 01
11:48:48:169 -> 01
11:48:48:521 -> 92
11:48:49:368 -> 92
11:48:50:329 -> 92
11:48:50:473 -> 01
11:48:51:384 -> c8
11:48:51:529 -> 03
11:48:52:312 -> 01
11:48:53:207 -> 8b
11:49:11:473 -> 01
11:49:13:360 -> 02
11:49:14:240 -> be
11:49:14:431 -> fe
11:49:15:200 -> 01
11:49:19:310 -> 00
12:02:04:725 -> 01
12:03:15:694 -> 6f
答案 0 :(得分:1)
由于时间太长,很难将这些数据可视化。这是一种你可以忽略的方法,没有收到字节的秒数:
d = """09:56:07:457 -> 7d
09:56:07:841 -> 91
09:56:09:008 -> 02
09:56:09:233 -> 80
09:56:09:345 -> 01
09:56:10:097 -> 80
09:56:10:448 -> 91
09:56:11:424 -> 01
09:56:11:552 -> 01
09:56:12:351 -> 01
09:56:12:607 -> 01
09:56:12:719 -> 01
09:56:13:711 -> 91
09:56:14:574 -> a3"""
import time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data = [i.split('->')[0].strip() for i in d.split("\n")]
#replace : with .
data = [i[:8]+"."+i[9:] for i in data]
#add date to beginning
data = ["2001-01-01 " + i for i in data]
#make new dataframe and convert strings to datetime index
df = pd.DataFrame({"ms":data})
#get milliseconds
df["ms"] = pd.to_datetime(df.ms)
#get whole seconds
df["seconds"] = [str(i)[0:19] for i in df["ms"]]
df["seconds"] = pd.to_datetime(df.seconds)
df.index = df.ms
df["bytes"] = [1 for _ in df.seconds]
print(df.head())
ms seconds bytes
ms
2001-01-01 09:56:07.457 2001-01-01 09:56:07.457 2001-01-01 09:56:07 1
2001-01-01 09:56:07.841 2001-01-01 09:56:07.841 2001-01-01 09:56:07 1
2001-01-01 09:56:09.008 2001-01-01 09:56:09.008 2001-01-01 09:56:09 1
2001-01-01 09:56:09.233 2001-01-01 09:56:09.233 2001-01-01 09:56:09 1
2001-01-01 09:56:09.345 2001-01-01 09:56:09.345 2001-01-01 09:56:09 1
df['string_seconds'] = [str(i) for i in df.seconds]
df = pd.DataFrame(df.string_seconds.value_counts())
df["seconds"] = pd.to_datetime(df.index)
df1 = df.sort_values('seconds')
df1.index = pd.DatetimeIndex(df1.index)
df1 = df1.iloc[1:]
df1.resample('1S')
df1.plot(x='seconds', y='string_seconds', figsize=(12,3))
这应该允许您查看每秒超过1个字节的频率。