How to Get Started With the Neo4j Graph Data Science Python Client

Learn the basic syntax of the newly released Python client for Neo4j Graph Data Science

pip install graphdatascience

Neo4j environment setup

Install Neo4j Graph Data Science Desktop. Image by the author.

Setting up the GDS Python client connection

gds.set_database("databaseName")
print(gds.version())

Executing Cypher statements

The signature of the run_cypher method. Image by the author.
Network of interactions in the first Harry Potter book. Image by the author
First five rows of the degree_df DataFrame. Image by the author.
Node degree distribution plot. Image by the author.

Projected graph object

Mapping between Cypher procedure and Python client method. Image by the author.
Mapping between Cypher procedure and Python client method. Image by the author.
Metadata of the projected graph. Image by the author.

Running graph algorithms

Mapping between the PageRank Cypher procedure and Python client method. Image by the author.
First five rows of the pagerank_df DataFrame. Image by the author.
  • nodeId: Internal node ids used to reference nodes
  • score: PageRank score
Top ten characters with the highest PageRank score. Image by the author.
Louvain algorithm metadata. Image by the author.
First five rows of the louvain_df DataFrame. Image by the author.
Count of members per community. Image by the author.

Helpful methods

Results of the gds.graph.list() method. Image by the author.
Find node id method syntax. Image by the author.

Conclusion

  • When specifying a map or a dictionary as a parameter to any method, make sure to add quotes around the keys
  • Instead of referencing the projected graph by its name, you need to input the Graph object as the first parameter of graph algorithms
  • Algorithm specific configuration parameter can be specified using keyword arguments
  • The streammode of graph algorithms outputs a Pandas DataFrame
  • Other algorithm modes like stats, write, and mutate output the metadata of the algorithm call as a Pandas Series

--

--

Developer Content around Graph Databases, Neo4j, Cypher, Data Science, Graph Analytics, GraphQL and more.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tomaz Bratanic

Data explorer. Turn everything into a graph. Author of Graph algorithms for Data Science at Manning publication.