我如何绘制其中包含pcap数据(如ip地址)的csv文件的图?

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

我将一个pcap文件转换为csv,现在想使用matplotlib或seaborn进行绘制,比如说python中的Source ip和Destination ip address列。我该怎么办?

dataframe = pd.read_csv("data.csv")
x = dataframe.Source
y = dataframe.Destination 

我如何对以上代码进行漂亮的绘制?和X和y的列中填充了ip地址预先感谢!

python python-3.x matplotlib data-visualization seaborn
1个回答
0
投票

我认为网络可视化适合您的需求。

首先,我定义一个玩具数据框

import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame([["IP112", "IP2"],
                   ["IP11", "IP2"],
                   ["IP13", "IP2"],
                   ["IP12", "IP24"],
                   ["IP111", "IP24"],
                   ["IP14", "IP205"],
                   ["IP12", "IP2"],
                   ["IP13", "IP205"]], columns=["Source", "Destination"])

现在,使用著名的库networkx进行可视化:

G = nx.Graph()
G.add_nodes_from(df.Source.unique())  # add 'Source' nodes
G.add_nodes_from(df.Destination.unique())  # add 'Destination' nodes
G.add_edges_from(df.values)  # add all edges
nx.draw(G, with_labels=True)
plt.show()

渲染:

enter image description here

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