#!/usr/bin/env python # coding: utf-8 # In[1]: # !pip install matplotlib pandas networkx version_information get_ipython().run_line_magic('load_ext', 'version_information') get_ipython().run_line_magic('version_information', 'networkx, cypher, pandas, matplotlib') # In[2]: get_ipython().run_line_magic('load_ext', 'cypher') # In[3]: get_ipython().run_line_magic('config', 'CypherMagic') # In[4]: get_ipython().run_line_magic('cypher', 'match (n)-[r]-() delete n, r') # In[5]: get_ipython().run_cell_magic('cypher', '', "create\n // Nodes\n (Neo:Crew {name:'Neo'}),\n (Morpheus:Crew {name: 'Morpheus'}),\n (Trinity:Crew {name: 'Trinity'}),\n (Cypher:Crew:Matrix {name: 'Cypher'}),\n (Smith:Matrix {name: 'Agent Smith'}),\n (Architect:Matrix {name:'The Architect'}),\n // Relationships\n (Neo)-[:KNOWS]->(Morpheus),\n (Neo)-[:LOVES]->(Trinity),\n (Morpheus)-[:KNOWS]->(Trinity),\n (Morpheus)-[:KNOWS]->(Cypher),\n (Cypher)-[:KNOWS]->(Smith),\n (Smith)-[:CODED_BY]->(Architect);\n") # In[6]: get_ipython().run_line_magic('cypher', 'match (n)-[r]-() return n, count(r) as degree order by degree desc') # In[7]: results = get_ipython().run_line_magic('cypher', 'match (n)-[r]-() return n.name as name, type(r) as rel, count(r) as degree order by degree desc') # In[8]: get_ipython().run_line_magic('matplotlib', 'inline') # In[9]: results.get_dataframe() # In[10]: results.plot() # In[11]: results.bar() # In[12]: results.pie() # In[13]: for i in range(1, 5): get_ipython().run_line_magic('cypher', 'match (n) return n, n.name limit {i}') # In[14]: results.dataframe # In[15]: print(results.csv()) # In[16]: get_ipython().run_line_magic('cypher', 'match (n)-[r]-() return n.name as name, type(r) as rel, count(r) as degree order by degree desc') # In[17]: get_ipython().run_line_magic('cypher', 'match (n)-[r]-() return n, type(r)') # In[18]: results = get_ipython().run_line_magic('cypher', 'match (n)-[r]-() return n, r') # In[19]: results # In[20]: import networkx as nx nx.draw(results.graph, with_labels=True) # In[21]: results.draw() # In[22]: from cypher import run run("match (n)-[r]-() return n.name as name, type(r) as rel, count(r) as degree order by degree desc")