Created
March 27, 2025 08:53
-
-
Save adam-cowley/df0ec9f7e207672cbfd0f501208d59fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reading CSV | |
import pandas as pd | |
csv = pd.read_csv('cluster.csv') | |
# connect with driver | |
from neo4j import GraphDatabase | |
driver = GraphDatabase.driver( | |
"neo4j+s://id.databases.neo4j.io", | |
("neo4j", "password") | |
) | |
# df -> list[dict] | |
rows = [ dict(row) for _, row in csv.iterrows() ] | |
# open a session | |
with driver.session() as session: | |
# Use rows to create values | |
session.run(""" | |
UNWIND $rows AS row | |
MERGE (c:Community {id: row.community_id}) | |
ON CREATE SET c.score = row.max_score | |
MERGE (s:System {id: row.system_id}) | |
MERGE (s)-[:in_community]->(c) | |
""", rows=rows) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment