【发布时间】:2019-12-27 08:17:05
【问题描述】:
我想把下面的数据放到一个neo4j 数据库中。 “朋友”列是由“,”分隔的一串 id。因此,应该有 10 个节点(id 为 1-10),其中我知道其中只有 5 个节点的年龄。我想在每个id和他们的朋友之间建立关系。
示例数据框
id age friends
1 10 "3,2"
2 20 "1,6"
3 15 "4,5,10"
4 13 "2,8,9"
5 25 "1,4,7"
我的代码是
LOAD CSV WITH HEADERS FROM 'file:///df.csv' AS line
MERGE (User {id: line.id, age: line.age})
LOAD CSV WITH HEADERS FROM 'file:///df.csv' AS line
UNWIND split(line.friends, ',') AS friends
MERGE (u:User {id: friends})
LOAD CSV WITH HEADERS FROM 'file:///df.csv' AS line
UNWIND split(line.friends, ',') AS friends
With line, friends
MERGE (User1{id: line.id})-[:FRIENDS]->(User2{id: friends})
这是正确的方法吗?以及如何简化代码?
【问题讨论】:
标签: python pandas csv neo4j cypher