Format for importing edgelist into igraph in python

社会主义新天地 提交于 2019-11-30 18:39:38

问题


What is the edgelist format accepted by igraph for import into python? What should the textfile that contains my weighted edges look like?

I've used igraph with R before, but don't have a working R installation on the machine I need to use---so I'm stuck in python.

I have an egelist.txt something like this:

123123, 321321, 1
222222, 333333, 2
123123, 333333, 3
222222, 321321, 4

...where the values are in (source, target, weight) form.

How would I import this in python? Or should I reformat my input?

I'm tentatively trying

import igraph

g = igraph.Graph.Read_Edgelist()

I can't tell how to set how to tell the import statement what to expect the order of my columns is, and my understanding from the documentation (http://hal.elte.hu/~nepusz/development/igraph/tutorial/tutorial.html) is that this will assume I have 321,321 nodes in play, rather than taking "321321" as a tagged ID for the node.


回答1:


Get rid of all the commas in your file (i.e. use only whitespace as the separator) and then use Graph.Read_Ncol. This should do the trick. The numeric IDs in your files will be assigned to the name vertex attribute and the edge weights will be stored in the weight edge attribute.



来源:https://stackoverflow.com/questions/14471473/format-for-importing-edgelist-into-igraph-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!