2
votes

I try to load the following nodes into Neo4j using load CSV with headers command:

id  label   name
0   Person  Dave
1   Person  Boris
2   Person  Rita
3   Person  Daniel
4   Person  Papa
5   Person  Mama

I save the Excel-Sheet as:

CSV UTF-8 (Comma delimited) (*.csv)

and the file location is:

 C:\Users\FY197T (2076902)\Documents\Neo4j\default.graphdb\import\nodes.csv

Opening in Editor looks like this:

id;label;name
0;Person;Dave
1;Person;Boris
2;Person;Rita
3;Person;Daniel
4;Person;Papa
5;Person;Mama

To load the nodes into Neo4j I use:

load csv with headers from "file:///nodes.csv" as persons create (p1:Person {nodeID:persons.id, label: persons.label, name: persons.name})

But what I get is:

Added 6 labels, created 6 nodes, completed after 105 ms.

So there are 6 nodes (as I have 6 rows), but none of them has any property

I already tried to save the file with different delimiters, or manually adding quotes. Latter gives:

there's a field starting with a quote and whereas it ends that quote
there seems to be characters in that field after that ending quote. That 
isn't supported. This is what I read: '"id"";"'

PS: I read all the other posts on this topic on stackoverflow, but none solved it yet for me

EDIT

1.

  load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons.label

gives:

 persons.label
 (empty)
 (empty)
 (empty)
 (empty)
 (empty)
 (empty)

2.

load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons

gives:

persons
{
   "id": "0",
   "label": "Person",
   "name": "Dave"
}
{
   "id": "1",
  "label": "Person",
   "name": "Boris"
 }
an so on....
2

2 Answers

2
votes

You can try with backticks:

    load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons.`label`;
1
votes

As you are using ; as the field separator, you should specify the FIELDTERMINATOR option. This way:

Using this CSV file:

id;label;name
0;Person;Dave
1;Person;Boris
2;Person;Rita
3;Person;Daniel
4;Person;Papa
5;Person;Mama

And this import script:

load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';'
create (p1:Person {nodeID:persons.id, label: persons.label, name: persons.name})

After the import, I ran this simple query over the graph:

MATCH (n) RETURN n

The result as text:

╒═══════════════════════════════════════════════╕
│"n"                                            │
╞═══════════════════════════════════════════════╡
│{"name":"Dave","label":"Person","nodeID":"0"}  │
├───────────────────────────────────────────────┤
│{"name":"Boris","label":"Person","nodeID":"1"} │
├───────────────────────────────────────────────┤
│{"name":"Rita","label":"Person","nodeID":"2"}  │
├───────────────────────────────────────────────┤
│{"name":"Daniel","label":"Person","nodeID":"3"}│
├───────────────────────────────────────────────┤
│{"name":"Papa","label":"Person","nodeID":"4"}  │
├───────────────────────────────────────────────┤
│{"name":"Mama","label":"Person","nodeID":"5"}  │
└───────────────────────────────────────────────┘