igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] python load attributes


From: Tuan Q. Phan
Subject: Re: [igraph] python load attributes
Date: Wed, 1 Jun 2011 16:34:01 -0400

Thanks Tamas for the comments.  What's the best format for ragged array of vertex attributes?  That is, I've been creating lists of attributes for each vertex, but gml and graphml writes it as a string.  I'd like to eventually easily import it into R and/or python for quick access.  There are a large number of sparse attributes, so the traditional way where each attribute has a name will require too much memory.

Thanks,
Tuan




On Sun, May 22, 2011 at 3:30 PM, Tamás Nepusz <address@hidden> wrote:
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.

-- 
T.

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.

Thanks,
Tuan
_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help


_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help




--
Tuan Q. PHAN
Doctor of Business Administration (Harvard)
cell: (213) 804-9432
skype: tuanqphan
address@hidden
http://www.tuanqphan.com



reply via email to

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