当前位置:   article > 正文

excel文件直接导入neo4j构建图谱_将excel中的数据制作neo4j

将excel中的数据制作neo4j
  1. from py2neo import Graph, Relationship, Node
  2. import xlrd
  3. g = Graph("xxx", username="neo4j", password="neo4j123")
  4. readbook = xlrd.open_workbook(r'xxx')
  5. sheet1 = readbook.sheets()[0]
  6. sheet_rows = sheet1.nrows
  7. for i in range(sheet_rows):
  8. if i == 0:
  9. continue # 第一行是实体、关系,故跳过第一行从第二行开始遍历
  10. start_node = Node("Person", name=sheet1.row_values(i)[0])
  11. end_node = Node("Person", name=sheet1.row_values(i)[1])
  12. relation = Relationship(start_node, sheet1.row_values(i)[2], end_node)
  13. g.merge(start_node, "Person", "name")
  14. g.merge(end_node, "Person", "name")
  15. g.merge(relation, "Person", "name")

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/506464
推荐阅读