[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] python load attributes

From: Tamás Nepusz
Subject: Re: [igraph] python load attributes
Date: Sun, 22 May 2011 21:30:56 +0200

Dear Tuan,

Neither the NCOL nor the edgelist format support attributes; your best bet is probably to use a different graph format if you want to store and load vertex/edge attributes together with the graph. The GML format is fairly easy to create and many other software packages support it. GraphML is another alternative but it's not very human-readable.

Alternatively, it takes only a few lines of code to facilitate loading vertex attributes from a CSV file. E.g.:

import csv
from itertools import izip

reader = csv.reader(open("attributes.csv"))
headers = reader.next()
for row in reader:
    vertex_id, attrs = row[0], row[1:]
    for attr_name, attr_value in izip(headers, attrs):
        graph.vs[vertex_id][attr_name] = attr_value

The above code assumes that you have a CSV file where the first column is the vertex ID, and the first row contains the names of the attributes you wish to add.

Even if you decide to do this, I'd strongly suggest to save your graph afterwards in GraphML or GML format to keep the attributes and the graph itself in the same file.


On Saturday, 21 May 2011 at 02:52, Tuan Q. Phan wrote:

Is there a python function to load vertex attributes?  I'm loading an edgelist/ncol, and would be nice to have a built-in attribute loading rather than doing it in python.

igraph-help mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]