IP地址直方图(熊猫系列)[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我希望绘制一个直方图来检查用于数据挖掘的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

但它仍然不一样。如何摆脱该值错误并显示合法的直方图?

python pandas ip-address data-mining valueerror
1个回答
1
投票

你需要一个定性的直方图

df['Source IP'].value_counts().plot(kind='bar')

Other SO question

© www.soinside.com 2019 - 2024. All rights reserved.