How to convert file from gml to edgelist in python

2019-07-17 19:57发布

问题:

Is there any example in python, how to convert file from *.gml to *.edgelist? Thank you

回答1:

In [1]:  import networkx as nx

In [2]:  g = nx.read_gml('gmlFile.gml')

In [3]:  nx.write_edgelist(g, 'edgelistFile.csv', delimiter=',')

Documentation

read_gml(path, encoding='UTF-8', relabel=False)

write_edgelist(G, path, comments='#', delimiter=' ', data=True, encoding='utf-8')[source]