Python将csv数据导入neo4j
# coding:utf-8 ########将csv数据导入neo4j#### import csv import py2neo from py2neo import Graph,Node,Relationship,NodeMatcher g=Graph('http://localhost:7474',user='neo4j',password='drmzju2022') with open('data2.csv','r',encoding='GBK') as f: print(f) reader = csv.reader(f) for item in reader: if reader.line_num == 0: continue print("当前行数:", reader.line_num, "当前内容:", item) start_node = Node("Person", name=item[0]) end_node = Node("Person", name=item[1]) relation = Relationship(start_node, item[3], end_node) g.merge(start_node, "Person", "name") #创建实体 g.merge(end_node, "Person", "name") #创建实体 g.merge(relation, "Person", "name") #创建关系 # # MATCH (p: Person {name:"贾宝玉"})-[k:丫鬟]-(r) # return p,k,r
效果展示:
参考B站up主视频学习而来,若侵权,请提醒删除。