使用py2neo操作neo4j
作者:互联网
from py2neo import Graph, Node, Relationship, NodeMatcher
# 连接neo4j 数据库
graph = Graph('bolt://192.168.0.210:7687', auth=("neo4j", "neo4j"))
# 获取标签为Fund的节点的属性名(SecurityName)的所有记录,并将其转为dataframe形式,否则只显示前三条
security_name = graph.run("MATCH (f:Fund) RETURN f.SecurityName").to_data_frame()
print(security_name)
#####################################################
'''query'''
# 查找节点标签类型为Stock,属性Symbol='000001'的节点
nodes = NodeMatcher(graph)
stock = nodes.match("Stock", Symbol='000001').first()
print(stock)
#####################################################
'''add'''
# 添加两个节点标签为Person,节点间关系为KNOWS的节点,MERGE 命令会自动使用事务进行操作
a = Node("Person", name='ZS', age=55)
b = Node("Person", name="LS", age=66)
KNOWS = Relationship.type("KNOWS")
graph.merge(KNOWS(a, b), "Person", "name")
####################################################
'''delete'''
# graph.delete(a) # 单个删除节点
# graph.delete(b)
# 删除所有标签类型为Person的节点和关系
graph.run('match (n:Person) detach delete n')
标签:name,py2neo,graph,Person,操作,neo4j,节点,delete 来源: https://blog.csdn.net/sinat_27747695/article/details/120769497