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()
title | year | |
---|---|---|
0 | Joe Versus the Volcano | 1990 |
1 | A League of Their Own | 1992 |
2 | Sleepless in Seattle | 1993 |
3 | Apollo 13 | 1995 |
4 | That Thing You Do | 1996 |
5 | You've Got Mail | 1998 |
6 | The Green Mile | 1999 |
7 | Cast Away | 2000 |
8 | The Polar Express | 2004 |
9 | The Da Vinci Code | 2006 |
10 | Charlie Wilson's War | 2007 |
11 | Cloud Atlas | 2012 |
4. 绘图
movies = graph.run("match (m:Movie) return m.released as year, m.title as title").to_data_frame()
movies.head()
year | title | |
---|---|---|
0 | 1999 | The Matrix |
1 | 2003 | The Matrix Reloaded |
2 | 2003 | The Matrix Revolutions |
3 | 1997 | The Devil's Advocate |
4 | 1992 | A 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.Graph()连接Neo4j报错:ImportError: cannot import name ‘clock‘ from ‘time‘ (unknown location)