简体   繁体   English

我如何使用2列Pandas DataFrame从python graphviz复制webgraphviz的结果

[英]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. 我使用了相同的数据集,看起来不错。

父子-WebGraphViz

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.

相关问题 如何使用 python 的 Pandas 库从 dataframe 中删除列? - How do I remove a column from a dataframe using Pandas library for python? 我如何使用 python pandas 数据框并使用列名和行名作为新列创建一个新表 - how do i take a python pandas dataframe and create a new table using the column and row names as the new column 如何使用 python 拆分 pandas 中的 dataframe 列值以获取另一列? - How do I split a dataframe column values in pandas to get another column using python? 在Python 3中使用Pandas,如何过滤掉数据框中某列中的重复字符串? - Using Pandas in Python 3, how do I filter out repeat strings in a column within a dataframe? 使用 Python,如何在保留/忽略所有“nan”值的同时删除 PANDAS dataframe 列中的重复项? - Using Python, how do I remove duplicates in a PANDAS dataframe column while keeping/ignoring all 'nan' values? How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame - How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame 如何使用 Pandas 在此 Dataframe 中创建列? - How do I create a column in this Dataframe using Pandas? 如何检查 dataframe 列是否包含来自另一个 dataframe 列的字符串并返回 python Z3A0524F883225EFFA94 中的相邻单元格 - How do I check if dataframe column contains a string from another dataframe column and return adjacent cell in python pandas? pandas - 我如何从同一列上的数据帧中获得差异 - pandas - how do i get the difference from a dataframe on the same column 如何将计算结果添加到数据框中的新列? - How do I add the results from a calculation to a new column in a dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM