Open geoHeil opened 3 years ago
Right now, there's no direct way to do this. You would have to graph.run(...).to_subgraph()
and then manually iterate through the nodes and relationships to convert them into NetworkX format.
Out of interest, how would you expect to map the node labels and relationship types onto a NetworkX graph?
Well a simple solution such as https://neo4j.com/labs/apoc/4.1/export/graphml/ what is happening for t.graphml.all
would do the job already i.e. having a Networkx MultiDiGraph with an edge attribute relationship_kin / node_kind to store the label /type and then all the attributer as key/value lookups.
This would be wonderful!
hi @geoHeil ,
i am not familiar with NetworkX but if you just need a graphml export what about a tiny CALL apoc.export.graphml.all(null, {stream:true})
?
from py2neo import Graph
g = Graph(name="test")
# Create testdata on db1
g.run("CREATE (n:MyNode) SET n.id = 1")
g.run("CREATE (n:MyNode2) SET n.id = 2")
# Extract data from db1
graphml = g.run(
"CALL apoc.export.graphml.all(null, {stream:true}) yield file, nodes, relationships, properties, data RETURN file, nodes, relationships, properties, data"
).to_data_frame()
print(graphml)
how can I export the graph to networkx which is obtained by running some cypher query?