Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create igraph Graph from pandas dataframe

I have the following pandas dataframe contains an edgelist as following:

        name1              name2    weight
0  $hort, Too  Alexander, Khandi  0.083333
1  $hort, Too             B-Real  0.083333

I want to create a igraph object from the pandas dataframe (not from files). The graph is too large so I cannot convert it to an adjacency matrix. How to do that?

like image 325
leonfrank Avatar asked Jun 06 '17 21:06

leonfrank


1 Answers

I was also looking for Networkx from_pandas_dataframe's function equivalent in igraph and I found using Graph.TupleList() as the best solution. so basically you create a tuple from 3 pandas columns and then use this function to create the network.

tuples = [tuple(x) for x in df.values]
Gm = igraph.Graph.TupleList(tuples, directed = True, edge_attrs = ['weight'])
like image 79
Rio Avatar answered Oct 07 '22 00:10

Rio