我希望绘制一个直方图来检查用于数据挖掘的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
但是还是不一样。如何消除该值错误并显示合法的直方图?