IP 地址直方图(熊猫系列)
Histogram of IP addresses (Panda Series)
我想绘制直方图来检查用于数据挖掘的 IP 地址的出现频率。
我的片段:-
import pandas as pd
import matplotlib.pyplot as plt
p1 = r'small_set.csv'
d = pd.read_csv(p1, engine='python')
source_ip = d['Source IP']
source_ip.hist()
我的'source_ip'是熊猫系列类型变量,如下所示:-
>>> source_ip
0 8.0.69.0
1 8.0.69.0
2 8.0.69.0
3 8.0.69.0
4 8.0.69.0
5 8.0.69.0
...
69 192.168.10.17
70 192.168.10.17
71 192.168.10.17
72 192.168.10.17
73 192.168.10.17
74 192.168.10.17
Name: Source IP, Length: 74, dtype: object
但是在第 source_ip.hist()
行,我收到以下错误:-
File "/home/developer/.local/lib/python2.7/site-packages/numpy/lib/histograms.py", line 253, in _get_outer_edges
"supplied range of [{}, {}] is not finite".format(first_edge, last_edge))
ValueError: supplied range of [inf, 8.0.69.0] is not finite
作为变通方法,我发现使用 value_counts()
的频率计数如下:-
s = d['Source IP'].value_counts()
>>> s
8.0.69.0 28
192.168.10.17 26
192.168.10.12 25
192.168.10.19 12
192.168.10.50 8
Name: Source IP, dtype: int64
但还是不一样。如何消除该值错误并显示合法的直方图?
您需要定性直方图
df['Source IP'].value_counts().plot(kind='bar')
我想绘制直方图来检查用于数据挖掘的 IP 地址的出现频率。
我的片段:-
import pandas as pd
import matplotlib.pyplot as plt
p1 = r'small_set.csv'
d = pd.read_csv(p1, engine='python')
source_ip = d['Source IP']
source_ip.hist()
我的'source_ip'是熊猫系列类型变量,如下所示:-
>>> source_ip
0 8.0.69.0
1 8.0.69.0
2 8.0.69.0
3 8.0.69.0
4 8.0.69.0
5 8.0.69.0
...
69 192.168.10.17
70 192.168.10.17
71 192.168.10.17
72 192.168.10.17
73 192.168.10.17
74 192.168.10.17
Name: Source IP, Length: 74, dtype: object
但是在第 source_ip.hist()
行,我收到以下错误:-
File "/home/developer/.local/lib/python2.7/site-packages/numpy/lib/histograms.py", line 253, in _get_outer_edges
"supplied range of [{}, {}] is not finite".format(first_edge, last_edge))
ValueError: supplied range of [inf, 8.0.69.0] is not finite
作为变通方法,我发现使用 value_counts()
的频率计数如下:-
s = d['Source IP'].value_counts()
>>> s
8.0.69.0 28
192.168.10.17 26
192.168.10.12 25
192.168.10.19 12
192.168.10.50 8
Name: Source IP, dtype: int64
但还是不一样。如何消除该值错误并显示合法的直方图?
您需要定性直方图
df['Source IP'].value_counts().plot(kind='bar')