Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-26-2020 06:07 PM
Hi everyone, I am trying to load a CSV file and the problem is that neo4j is not recognizing the headers and does not split the data in columns and basically considers each row as a list.
Another interesing aspect is that at the begining and ending of each row the data is between curly braces { }.
I am attaching a sample image of the dataset and an also the result in Neo4j
Thank you
Solved! Go to Solution.
07-27-2020 07:24 PM
07-26-2020 10:33 PM
The data from .csv is incomplete and and apparently the data columns you presented is not being seen. Please post one full row of your .csv file so that I can help you. I did lot of .csv file imports from Neo4j versions from 3.0 to 4.1.1.
07-27-2020 06:24 AM
07-27-2020 02:22 PM
Thanks for the data file. As the column headers have blank spaces, you must include the column headers between back tics. Here is the Cypher that I used to import sample data. Also for null values please use COALESCE function.
LOAD CSV WITH HEADERS FROM "file:/subset1.csv" AS row
with row
MERGE (a:Col1 {col1: row.`?UID`})
MERGE (a1:Col2 {col2: row.`Anno Cargue SECOP`})
MERGE (a2:Col3 {col3: row.`Anno Firma del Contrato`})
MERGE (a3:Col4 {col4: row.`Nivel Entidad`})
RETURN a, a1, a2, a3
Created four nodes.
Here is the code with COALESCE function:
MERGE (a20:Col21 {col21: COALESCE(row.`Municipios Ejecucion`, 'NA')})
This created a node with col21 = 'NA'. This default value can be anything.
You can use COALESCE function for every column value. This inserts the default value only when the column value is null.
Hope this helps you.
07-27-2020 07:14 PM
Thank you, now I managed to load the several rows of the dataset
Best regards
07-27-2020 07:24 PM
Glad it worked! Appreciate your comments.
08-30-2020 07:57 PM
Hi, ameyasoft, thanks again for your help. I wonder if you can help me again since I am trying to load a similar CSV file whith the following data model
I am using the following code
LOAD CSV WITH HEADERS FROM "file:/10.csv" AS row
with row
MERGE (a:CONTRATANTE {`NIT de la Entidad`: row.`NIT de la Entidad`, `Nivel Entidad`: row.`Nivel Entidad`})
MERGE (b:CONTRATO {UID: row.`?UID`, `Cuantia Contrato_CUANT`: row.`Cuantia Contrato_CUANT`})
MERGE (c:CONTRATISTA {`Identificacion del Contratista`: row.`Identificacion del Contratista`, `Nom Raz Social Contratista`: row.`Nom Raz Social Contratista`})
MERGE (a) -[r:EMITE]-> (b)
MERGE (b) -[s:ASIGNA]-> (c);
But I am getting an error related with a missing value while I do not have one
`Cannot merge node using null property value for Nivel Entidad (Failure when processing file....on line 2.)`
Thank you
10.txt (8.6 KB)
08-31-2020 10:54 AM
Thanks for sharing the file. My first suspicion was back tics in the header column. I copied your file into my import directory and tested. After the LOAD CSV statement I tried to return 4 rows (RETURN row limit 4) it shows the data with column names enclosed in back tics. Then I tried
RETURN row.`?UID` or row.`Nivel Entidad`
both returning null values. The problem is with back tic in the column hearders. I deleted the back tics from the header row and used the updated file Ran the above query and both produced correct data.
Solution: Just remove the back tics in the header column and use your Cypher query and it should run . You need to keep the back tics in your Cypher query and not in the header column. Try and let me know.
08-31-2020 07:28 PM
Hi ameyasoft, it worked thank you very much
Mau
08-31-2020 08:30 PM
All is well that ends well!!
All the sessions of the conference are now available online