Neo4j Python Integration

This is a companion notebook for the new Data Science Solutions book. The code is explained in the book.

This notebook provides Python sample code to access Neo4j API. It assumes that you are running a local Neo4j server with user/password credentials as supplied and accessing the data science graph database available at Startupsci GitHub.


In [70]:
import py2neo
import pandas as pd

password = 'demo'
samples = 20

graph = py2neo.Graph(password)

query = """
    MATCH (d:Datasource)
    WHERE rand() <= 0.1
    RETURN Labels(d) as labels, d.name as name,
    d.about as about, d.link as link LIMIT {}
    """.format(samples)

df = pd.DataFrame(graph.data(query))
df = df.loc[:, ['name', 'about', 'link', 'labels']]
df


Out[70]:
name about link labels
0 Journal of Journal of Cell Biology DataViewer http://jcb-dataviewer.rupress.org [Datasource, Public, Access]
1 Psychiatric Genomics Psychiatric Genomics Consortium https://www.med.unc.edu/pgc/downloads [Datasource]
2 UCSC Public UCSC Public Data http://hgdownload.soe.ucsc.edu/downloads.html [Datasource, Public, Access]
3 UnitProt Universal Protein Resource (UnitProt) http://www.uniprot.org/downloads [Datasource, Public, Access]
4 Aviation Weather Center Aviation Weather Center - Consistent, timely a... https://aviationweather.gov/adds/dataserver [Datasource, Public, Access]
5 updated monthly Climate Data from UEA (updated monthly) https://crudata.uea.ac.uk/cru/data/temperature... [Datasource, Public, Access]
6 NOAA Climate NOAA Climate Datasets http://www.ncdc.noaa.gov/data-access/quick-links [Datasource, Public, Access]
7 UEA Climatic UEA Climatic Research Unit http://www.cru.uea.ac.uk/data [Datasource]
8 WU Historical WU Historical Weather Worldwide https://www.wunderground.com/history/index.html [Datasource]
9 Open Data Monitor Open Data Monitor http://opendatamonitor.eu [Datasource, DataCatalog, Tool, Public, Access]
10 Stanford Longitudinal Stanford Longitudinal Network Data Sources http://stanford.edu/group/sonia/dataSources/in... [Datasource]
11 The Nexus The Nexus Network Repository http://nexus.igraph.org/ [Datasource, Public, Access]
12 Challenges in Challenges in Machine Learning http://www.chalearn.org/ [Datasource, Public, Access]
13 AEA American Economic Association (AEA) https://www.aeaweb.org/resources/data [Datasource, Public, Access]
14 The Atlas The Atlas of Economic Complexity http://atlas.cid.harvard.edu [Datasource]
15 TIGER/Line TIGER/Line - U.S. boundaries and roads http://www.census.gov/geo/maps-data/data/tiger... [Datasource, Public, Access]
16 YouTube Faces YouTube Faces Database http://www.cs.tau.ac.il/~wolf/ytfaces/ [Datasource]
17 Machine Learning Machine Learning Data Set Repository http://mldata.org/ [Datasource, Public, Access]
18 CLiPS Stylometry CLiPS Stylometry Investigation Corpus http://www.clips.uantwerpen.be/datasets/csi-co... [Datasource]
19 Wikidata Wikidata - Wikipedia databases https://www.wikidata.org/wiki/Wikidata:Databas... [Datasource, Public, Access]