from py2neo import Graph, Relationship, Node
import xlrd
g = Graph("xxx", username="neo4j", password="neo4j123")
readbook = xlrd.open_workbook(r'xxx')
sheet1 = readbook.sheets()[0]
sheet_rows = sheet1.nrows
for i in range(sheet_rows):
if i == 0:
continue # 第一行是实体、关系,故跳过第一行从第二行开始遍历
start_node = Node("Person", name=sheet1.row_values(i)[0])
end_node = Node("Person", name=sheet1.row_values(i)[1])
relation = Relationship(start_node, sheet1.row_values(i)[2], end_node)
g.merge(start_node, "Person", "name")
g.merge(end_node, "Person", "name")
g.merge(relation, "Person", "name")
excel文件直接导入neo4j构建图谱
最新推荐文章于 2025-04-18 07:54:48 发布