学习记录-py2neo:Neo4j数据库的python驱动

安装:

  • 直接在命令行pip3 install py2neo
  • 官网下载(解压后放到python下的scripts中,在py2neo目录下cmd,输入python setup.py install

链接

auth=(用户名,密码)

from py2neo import Graph,Node,Relationship
graph = Graph("http://localhost:7474",auth=("neo4j","password"))
  • 问题:unauthorized(self.uri.string)

  • 解决方法:

    from py2neo import authenticate,Graph
    authenticate("localhost:7474","账号","密码")
    graph = Graph("http://localhost:7474/db/data")
    

创建节点和关系

(已通过batch-import导入,这步省略

a = Node("Person", name="Alice")
b = Node("Person", name="Bob")
ab = Relationship(a, "KNOWS", b)
graph.create(ab)

查询

查询节点(使用原生查询语句
from py2neo import authenticate,Graph
graph = Graph("http://localhost:7474",auth=("neo4j","password"))

str = "match (变量名a:标签名{属性名:特定属性值}) return a"
x = graph.run(str).data()
y = pd.DataFrame(x)
posted @ 2020-07-29 11:17  19呀  阅读(292)  评论(0编辑  收藏  举报