cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Doesn't import properties when using LOAD CSV command

shanna
Node Clone

I am using the line of code below to import a very simple csv file for testing. The data is imported, however, the properties are not. What could be the problem here? Any ideas?

/// My line of code

LOAD CSV WITH HEADERS FROM "file:///test1.csv" AS row
CREATE (n:naam {bedrijf:row.bedrijf})
CREATE (l:leeftijd)
CREATE (n)-[:IS]->(l);

///My csv file which is called test1
naam; bedrijf; leeftijd
Pietje Puk; Annechien; 28

1 ACCEPTED SOLUTION

shanna
Node Clone

Thanks to all the great advice below, my final solution was a combination of using the FIELDTERMINATOR clause and adjusted the raw CSV file so that there where no more spaces between the values.

Because I at first wanted to make my code as clean as possible, I wanted to change the separators from semicolon to comma in my settings. But I found that, because I am working on a Mac, this turns out to be quite a hassle. Therefore, the FIELDTERMINATOR clause was eventually part of my solution.

View solution in original post

14 REPLIES 14

omerule
Graph Buddy

Beste Shana,
You can add FIELDTERMINATOR ";" to your import line.
And to get a test sample of the data you want to import you can use RETURN row.bedrijf LIMIT 3.
And you can take a look at this tutorial:
Watch “1120 - Using Load CSV in the Real World” on Vimeo: https://vimeo.com/112447027?ref=em-share.

Yours Kindly, Omer

CSV is "Comma Seperated Values"

What you have, isn't technically a csv.

ameyasoft
Graph Maven
Try this:

LOAD CSV WITH HEADERS FROM "file:///test1.csv" AS row
CREATE (n:naam {bedrijf:row. bedrijf})
CREATE (l:leeftijd {leeftijd: row. leeftijd})
CREATE (n)-[:IS]->(l);

There is a blank space before second and third column headers. You have to include that blank space before 'bedrijf' and 'leeftijd'

Basically this. Your CSV file isn't formatted right, the spaces between the values result in the property keys being prefixed with a space, and with the property values also being prefixed with a space (excepting the first property key and value, since those don't have spaces before them in your CSV). Eliminate the spaces in your CSV following the semicolons and then it should import your data properly.

One can use lTrim function to eliminate the leading white spaces in the property values.

The trim function will work for the property values, yes, but the header line needs some fixing so that the property keys don't include leading whitespace.

shanna
Node Clone

Thanks to all the great advice below, my final solution was a combination of using the FIELDTERMINATOR clause and adjusted the raw CSV file so that there where no more spaces between the values.

Because I at first wanted to make my code as clean as possible, I wanted to change the separators from semicolon to comma in my settings. But I found that, because I am working on a Mac, this turns out to be quite a hassle. Therefore, the FIELDTERMINATOR clause was eventually part of my solution.

It will be easier to follow CSV standards.

  • Lines terminated by \n
  • Fields terminated by , and enclosed by "
column1, column2, column3
"Val 1", "Any other value with spaces", 123.887

In that format, the file can be imported into just about anything, very simply and cleanly.

If the file is coming from a third party where the user has no control on the format and still wants to import data into Neo4j database what options the user has?

Really depends on the context, and where/how you're getting the file. If you're automating it, then I'd do my best to try to work with that third-party to get it in csv format, or convert it after downloading.

This is not a practical solution!

Check these links for practical solutions:

https://community.neo4j.com/t/trouble-with-split-and-unwind-syntax/28035/4

https://community.neo4j.com/t/many-to-many-relations-reading-from-csv-file/27743/5

What do you mean by "this isn't a practical solution"?

I think a more practical solution to this approach would be to import the data from 1 or more CSVs in RDBMS system and then pull that data into a standard format that ETL tools supported by Neo4j can accept. The frequency and mechanism of Data Sync between RDBMS and Neo4j can be decided after a discussion with Solution Architects and Developers.

@ameyasoft,
If you have a related question, perhaps you should open a new post, and provide more details and context so we can better help you.