Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format for importing edgelist into igraph in python

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.

like image 648
Mittenchops Avatar asked Jun 22 '26 22:06

Mittenchops


1 Answers

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.

like image 73
Tamás Avatar answered Jun 24 '26 11:06

Tamás



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!