neo4j logo neo4j: data

1 2 3 4 5 6 7 8 9 10

We're going to load the nodes first. To do that you need to run the following query.

LOAD CSV WITH HEADERS FROM 'file:///nodes.csv' AS line
CREATE (:Project {name: line.project})

This creates nodes of type Project and also attaches a property called name. Given that the nodes now exist, we can start connecting them with edges.

LOAD CSV WITH HEADERS FROM 'file:///dependencies.csv' AS line
MERGE (p:Project {name: line.project})
MERGE (d:Project {name: line.dep})
CREATE (p)<-[:Dependency]-(d)

Let's unpack what is happening in that query. We're first looking for nodes p and d that match the name that is in each line of the csv file. Given a match, we add an edge between them. Each edge will also have a type attached. In our case it is Dependency.


We're keeping the demo simple here, but you can imagine database instances where we have many different types of nodes and edges.

First Query

With the data loaded we can start asking questions! Let's check for projects that scikit-learn depends on.

MATCH (n1:Project)-->(n2:Project {name: "scikit-learn"})