[英]How do I reproduce results from webgraphviz with python graphviz using 2 column pandas dataframe
I have a two column pandas dataframe with parent and child process id's that looks like the following: 我有一个两列的pandas数据框,其父进程和子进程的ID如下所示:
ChildID ParentID
0 460 580
1 580 716
2 460 724
3 716 840
4 716 812
5 724 884
6 716 800
7 1424 2028
8 2280 2368
9 2368 2480
10 2948 2916
11 3312 3896
12 3312 3468
13 3312 3996
16 4 460
17 460 480
18 3244 4168
19 1324 4796
20 5888 5048
21 2504 4424
22 1324 7584
23 2040 1400
24 1224 2452
.. ... ...
I have downloaded the graphviz python library, but in the meantime to see what I could do I headed over to http://www.webgraphviz.com/ to see what could be done. 我已经下载了graphviz python库,但是与此同时,看我能做什么,我去了http://www.webgraphviz.com/ ,看看能做什么。 I used the same dataset and it looks pretty good. 我使用了相同的数据集,看起来不错。
I have searched a bit but am having trouble finding a good way to replicate this using the python library graphviz. 我已经搜索了一下,但是很难找到使用python库graphviz复制此内容的好方法。 Can anyone point me in the right direction just using 2 columns with possibly a small example? 任何人都可以仅使用2列(可能仅举一个小例子)来指出正确的方向吗?
Here is my solution: 这是我的解决方案:
from graphviz import Graph
g = Graph('processs', filename='process.gv', engin='sfdp')
# run over all the rows and for each row add a new edge to the graph
for index, row in df.iterrows():
g.edge(str(row['ChildID']), str(row['ParentID']))
g.view()
If you have some problems with running graphviz on windows you probably need to add graphviz's bin files to the windows PATH, to do so you can use: 如果在Windows上运行graphviz时遇到一些问题,则可能需要将graphviz的bin文件添加到Windows PATH中,为此,您可以使用:
import os
os.environ["PATH"] += os.pathsep + <path to the bin folder>
Enjoy! 请享用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.