Py2neo成功连接Neo4j初探:Movie Graph

Posted ZSYL

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Py2neo成功连接Neo4j初探:Movie Graph相关的知识,希望对你有一定的参考价值。

Py2neo连接Neo4j初探:Movie Graph

1. 导包

import py2neo
import matplotlib.pyplot as plt

2. 连接Neo4j

graph = py2neo.Graph('http://localhost:7474/browser/', auth=('neo4j', 'zs'))

3. 执行语句

query = '''
        match (m: Movie) return m
'''
graph.run(query).to_data_frame().head()
m
0{'tagline': 'Welcome to the Real World', 'titl...
1{'tagline': 'Free your mind', 'title': 'The Ma...
2{'tagline': 'Everything that has a beginning h...
3{'tagline': 'Evil has its winning ways', 'titl...
4{'tagline': 'In the heart of the nation's capi...
# graph.run("CALL db.schema.visualization()").data()
graph.run("match (p:Person)-[r:ACTED_IN]->(m:Movie) where p.name='Tom Hanks' return m.title as title, m.released as year order by m.released").to_data_frame()
titleyear
0Joe Versus the Volcano1990
1A League of Their Own1992
2Sleepless in Seattle1993
3Apollo 131995
4That Thing You Do1996
5You've Got Mail1998
6The Green Mile1999
7Cast Away2000
8The Polar Express2004
9The Da Vinci Code2006
10Charlie Wilson's War2007
11Cloud Atlas2012

4. 绘图

movies = graph.run("match (m:Movie) return m.released as year, m.title as title").to_data_frame()
movies.head()
yeartitle
01999The Matrix
12003The Matrix Reloaded
22003The Matrix Revolutions
31997The Devil's Advocate
41992A Few Good Men
movies.groupby('year').count().plot(kind='bar')  # movies.groupby('year').agg(count).plot(kind='bar')
plt.show()


加油!

感谢!

努力!

以上是关于Py2neo成功连接Neo4j初探:Movie Graph的主要内容,如果未能解决你的问题,请参考以下文章

知识图谱Py2neo操作Neo4j使用教程

Py2neo.Graph()连接Neo4j报错:ImportError: cannot import name ‘clock‘ from ‘time‘ (unknown location)

连接在py2neo中止

知识图谱Python.py2neo操作Neo4j

知识图谱py2neo基本操作(2021-11-11)

neo4j & py2neo使用过程中踩过的坑