Rocking chief
Rocking chief

Reputation: 1069

How do I plot a graph from CSV files in neo4j

I want to plot a graph from CSV files. I have two CVS files. The first has the node IDs with node descriptions. It looks something like:

nodeID1  Feature1  Feature2  Feature3 Label
nodeID2  Feature1  Feature2  Feature3 Label
nodeID3  Feature1  Feature2  Feature3 Label

The second says how the nodes connect. It looks something like:

nodeID1 nodeID2
nodeID2 nodeID3

In the above case, there are two links, namingly nodeID1-nodeID2 and nodeID2-nodeID3.

My question is given these two CVS files, is there an easy way I can construct the graph in Neo4j or any other graph database that I can visualize my results?

Upvotes: 0

Views: 307

Answers (1)

vhorta
vhorta

Reputation: 76

You can first create all the nodes with something like:

USING PERIODIC COMMIT 5000 LOAD CSV WITH HEADERS FROM "file:///c:/nodes.csv" AS line
CREATE (n:Node { nodeId: toInt(line.nodeId), feature1: line.feature1, feature2: linefeature2 })

Then you can match the nodes and create the relationships based on the other csv file:

USING PERIODIC COMMIT 500 LOAD CSV WITH HEADERS FROM "file:///c:/relationships.csv" AS line
MATCH (n:Node { nodeId: toInt(line.nodeId1)}),(n2:Node { nodeId: toInt(line.nodeId2)})
CREATE (n)-[:RelType]->(n2)

Upvotes: 2

Related Questions