Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-22-2020 07:52 AM
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
Solved! Go to Solution.
10-27-2020 01:16 AM
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.
10-22-2020 10:58 AM
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
10-22-2020 02:01 PM
CSV is "Comma Seperated Values"
What you have, isn't technically a csv.
10-22-2020 03:19 PM
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'
10-22-2020 03:49 PM
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.
10-22-2020 09:12 PM
One can use lTrim function to eliminate the leading white spaces in the property values.
10-23-2020 07:20 AM
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.
10-27-2020 01:16 AM
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.
10-27-2020 10:06 AM
It will be easier to follow CSV standards.
\n
,
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.
10-27-2020 07:51 PM
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?
10-28-2020 09:46 AM
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.
10-28-2020 09:50 PM
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
10-28-2020 11:27 PM
What do you mean by "this isn't a practical solution"?
10-29-2020 03:01 AM
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.
10-29-2020 08:57 AM
@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.
All the sessions of the conference are now available online