I have a networkx graph with some list and dict attributes that the function nx.write_graphml doesn't accept as valid type for the export. I couldn't find a function that would automatically ignore those attributes so I decided to create one myself.
I know that int, float and string are accepted, but I don't know if there are others and, if so, which ones.
The
graphmlformat followsXMLstructure and according to the docs, the following data types are accepted:If the lists are not too long, then one suggestion is to create numbered attributes (e.g.
colour_1,colour_2). Similarly, for dictionaries. This is not convenient, but these aregraphmlconstraints.Also, if you do not intend to use the
listordictin Gephi, but want to preserve them for later use, then one option is to convert them to a string representation using something likejson.dumps.Update: when writing the data,
networkxwill try to convert the data types to the allowed representations. For example, the list ofnumpy-specific conversions can be found here.