I have a graph built using the networkx package in Python that has data attributes associated with both nodes and edges. These attributes are dictionaries (or lists) themselves with nested dictionaries. I cannot figure out how to write this graph in .gexf (or .graphml, etc.) format due to the data type.
Is there a way to get write_gexf to parse these data types in XML? or is there any other workaround?
Here is an example:
1 import networkx as nx 2 3 G = nx.graph() 4 G.add_node(0, attr1 = { 'name1' : 'Alice', 'name2' : 'Bob' }, attr2 = 5) 5 G.add_node(0, attr1 = { 'name1' : 'Calvin', 'name2' : 'Hobbes' }, attr2 = 6) 6 G.add_edge(0,1, likes = ['milk', 'oj']) 7 8 nx.write_gefx(G,"test.gefx")
which gives an error:
Traceback (most recent call last): File "so_write_gefx.py", line 8, in <module> nx.write_gexf(G,"test.gexf") ... line 378, in add_attributes for val,start,end in v: ValueError: too many values to unpack
source share