问题
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