Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read edges from .csv file to igraph using python

Tags:

python

csv

igraph

Let's say I have a .csv file containing the following:

Apple    Banana
Apple    Coconut
Banana   Coconut
Coconut  Apple

And these should mean directed edges between two nodes, like: Apple->Banana, Apple->Coconut, etc.

What is the proper method to use this kind of input in igraph?

like image 292
Klajbar Avatar asked Jul 06 '26 13:07

Klajbar


1 Answers

This is what the Read_Ncol(f, names=True, weights="if_present", directed=True) function exactly does.

http://igraph.org/python/doc/igraph-pysrc.html#GraphBase.Read_Ncol

>>> from igraph import *
>>> g = Graph.Read_Ncol("stuff.csv", directed=True)
like image 54
Klajbar Avatar answered Jul 08 '26 03:07

Klajbar



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!