Extracting an edge list from Neo4j is quite straightforward since we only need two pieces of information: the source node and the target node, linked together by a relationship. Considering our graph is undirected, we can use the following Cypher query to extract the pair of nodes linked together through a relationship of the LINK type:
MATCH (n:Node)-[r:LINK]-(m:Node)
RETURN n.id as source, m.id as target
So, similar to what we did in the previous chapters, we can extract this data using the Neo4j Python driver:
from neo4j import GraphDatabase
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "<YOUR_PASSWORD>"), encrypted=False)
with driver.session() as session:
res = session.run("""
MATCH (n:Node)-[r:LINK]-(m:Node)
RETURN n.id as source, m.id as target
""")
The result object, res, can then be exploited to create a new DataFrame...