Skip to content

Instantly share code, notes, and snippets.

@innat
Created April 9, 2019 18:19
Show Gist options
  • Select an option

  • Save innat/17fc7ea6ac79798b0454fbd429d11c8a to your computer and use it in GitHub Desktop.

Select an option

Save innat/17fc7ea6ac79798b0454fbd429d11c8a to your computer and use it in GitHub Desktop.
Imported Data into Neo4j

//One way to "clean the slate" in Neo4j before importing (run both lines):

match (a)-[r]->() delete a,r

match (a) delete a

//Script to Import Data Set: test.csv (simple road network)

//For Windows use something like the following

//[NOTE: replace any spaces in your path with %20, "percent twenty" ]

LOAD CSV WITH HEADERS FROM "file:///C:/coursera/data/test.csv" AS line

MERGE (n:MyNode {Name:line.Source})

MERGE (m:MyNode {Name:line.Target})

MERGE (n) -[:TO {dist:line.distance}]-> (m)

//For mac OSX use something like the following

//[NOTE: replace any spaces in your path with %20, "percent twenty" ]

LOAD CSV WITH HEADERS FROM "file:///coursera/data/test.csv" AS line

MERGE (n:MyNode {Name:line.Source})

MERGE (m:MyNode {Name:line.Target})

MERGE (n) -[:TO {dist:line.distance}]-> (m)

//Script to import global terrorist data

LOAD CSV WITH HEADERS FROM "file:///Users/jsale/sdsc/coursera/data/terrorist_data_subset.csv" AS row

MERGE (c:Country {Name:row.Country})

MERGE (a:Actor {Name: row.ActorName, Aliases: row.Aliases, Type: row.ActorType})

MERGE (o:Organization {Name: row.AffiliationTo})

MERGE (a)-[:AFFILIATED_TO {Start: row.AffiliationStartDate, End: row.AffiliationEndDate}]->(o)

MERGE(c)<-[:IS_FROM]-(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment