Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

networkx export of the graph #893

Open
geoHeil opened this issue Apr 29, 2021 · 4 comments
Open

networkx export of the graph #893

geoHeil opened this issue Apr 29, 2021 · 4 comments

Comments

@geoHeil
Copy link

geoHeil commented Apr 29, 2021

how can I export the graph to networkx which is obtained by running some cypher query?

@technige
Copy link
Collaborator

technige commented May 5, 2021

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?

@geoHeil
Copy link
Author

geoHeil commented May 5, 2021

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.

@priamai
Copy link

priamai commented Aug 30, 2021

This would be wonderful!

@motey
Copy link

motey commented Oct 7, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants