Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can import edgelist to igraph python

Tags:

python

igraph

I have a list of twitter followers in text file that I want to import to iGraph.

Here's the sample of my list

393795446 18215973
393795446 582203919
393795446 190709835
393795446 1093090866
393795446 157780872
393795446 1580109739
393795446 3301748909
393795446 1536791610
393795446 106170345
393795446 9409752

And this is how I import it

from igraph import *
twitter_igraph = Graph.Read_Edgelist('twitter_edgelist.txt', directed=True)

But I get this error.

---------------------------------------------------------------------------
InternalError                             Traceback (most recent call last)
<ipython-input-10-d808f2237fa8> in <module>()
----> 1 twitter_igraph = Graph.Read_Edgelist('twitter_edgelist.txt', directed=True)

InternalError: Error at type_indexededgelist.c:369: cannot add negative number of vertices, Invalid value

I'm not sure why it's saying something about negative number. I check the file and it doesn't have any negative number or id.

like image 616
toy Avatar asked Mar 14 '23 19:03

toy


1 Answers

You need to use graph.Read_Ncol for this type of file format. Why your file doesn't conform to a typical "edgelist" format is beyond me. I've wondered this myself many times. I should also mention that I grabbed the answer from here. Tamàs seems to be the main igraph guy around here. I'm sure he can give a more detailed reason as to why you need to use Ncol as opposed to Edgelist.

This works for me.

from igraph import *
twitter_igraph = Graph.Read_Ncol('twitter_edgelist.txt', directed=True)

Personal Plug

This is a great example of where igraph's documentation could be improved.

For example: The only accompanying text with graph.Read_Edgelist() doc says...

Reads an edge list from a file and creates a graph based on it. Please note that the vertex indices are zero-based.

This doesn't really tell me anything when obviously there are nuances with how the file needs to be formatted. Saying what format this function expects the file to be in would save a lot of people their sanity.

like image 191
Austin A Avatar answered Mar 29 '23 00:03

Austin A