2

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....
Grapheneer
  • 897
  • 8
  • 25

2 Answers2

2

You can try with backticks:

    load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons.`label`;
szenyo
  • 522
  • 2
  • 9
1

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"}  │
└───────────────────────────────────────────────┘
Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
  • unfortunately I get the same result: Added 6 labels, created 6 nodes – Grapheneer Aug 17 '17 at 16:18
  • 1
    @Boris very weird... I copied and pasted your CSV data into a file called `nodes.csv` inside the import directory. After added the `FIELDTERMINATOR` option all works... Can you share your raw CSV file that is stored inside the import dir, please? – Bruno Peres Aug 17 '17 at 16:26
  • https://www.dropbox.com/s/cnfjhzf9vt2tpj8/nodes.csv?dl=0 Yes very weird, maybe something in the .conf file? – Grapheneer Aug 17 '17 at 16:35
  • 1
    @Boris, same result with your CSV. All works fine. I'm working over a Linux machine. – Bruno Peres Aug 17 '17 at 16:40
  • 1
    @Boris what is the output of `load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons`? – Bruno Peres Aug 17 '17 at 16:46
  • good idea - now it displays all the properties (see EDIT) so the issue is with referencing to the headers? – Grapheneer Aug 17 '17 at 16:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152182/discussion-between-bruno-peres-and-boris). – Bruno Peres Aug 17 '17 at 16:57