Skip to content

Instantly share code, notes, and snippets.

@adam-cowley
Created March 27, 2025 08:53
Show Gist options
  • Save adam-cowley/df0ec9f7e207672cbfd0f501208d59fb to your computer and use it in GitHub Desktop.
Save adam-cowley/df0ec9f7e207672cbfd0f501208d59fb to your computer and use it in GitHub Desktop.
# 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