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?
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'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With