Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-04-2021 06:09 AM
I have the following CSV:
id attr value
1 abc 1.1
1 eww -9.4
1 ssv likj
2 we2 1
2 eww 900
3 kuku -91
3 lulu 383
3 ssv bubu
I would like to create 3 nodes that consists of:
Node 1: {id:1, abc: 1.1, eww: -9.4, ssv: "likj"}
Node 2: {id:2, we2: 1, eww: 900}
Node 3: {id:3, kuku: -91, lulu: 383, ssv: "bubu"}
How can I build it in Neo4j cypher?
Solved! Go to Solution.
11-08-2021 12:48 AM
In your CSV, the first column doesn't have a column name so in the map
object you have a key which has ""
as name and that's why you have this error.
So this query will remove the column with no name then load nodes:
WITH "https://drive.google.com/u/0/uc?id=1kcNZm0A2I3k9xN1IfNRITOHEzdnqgG7e&export=download" AS requests_url
CALL apoc.load.csv(requests_url)
YIELD map
WITH apoc.map.clean(map, [""], []) AS map
MERGE (n:Node {request_id: map.request_id})
SET n += map
11-04-2021 06:57 AM
Hello @steve5
This should work with apoc.load.csv() function:
CALL apoc.load.csv('file:///data.csv')
YIELD map
MERGE (n:Node {id: map.id})
SET n += map
Regards,
Cobra
11-07-2021 11:32 PM
Because you have to use APOC to laod your CSV. I used the apoc.load.csv()
function and not LOAD CSV
.
11-08-2021 12:06 AM
This should work:
WITH "https://drive.google.com/u/0/uc?id=1kcNZm0A2I3k9xN1IfNRITOHEzdnqgG7e&export=download" AS requests_url
CALL apoc.load.csv(requests_url)
YIELD map
MERGE (n:Node {id: map.id})
SET n += map
11-08-2021 12:48 AM
In your CSV, the first column doesn't have a column name so in the map
object you have a key which has ""
as name and that's why you have this error.
So this query will remove the column with no name then load nodes:
WITH "https://drive.google.com/u/0/uc?id=1kcNZm0A2I3k9xN1IfNRITOHEzdnqgG7e&export=download" AS requests_url
CALL apoc.load.csv(requests_url)
YIELD map
WITH apoc.map.clean(map, [""], []) AS map
MERGE (n:Node {request_id: map.request_id})
SET n += map
11-08-2021 02:59 AM
@Cobra
I have changed the URL but still it doesn't work. Please have a look:
WITH "xxxxxxxxx" AS requests_url
CALL apoc.load.csv(requests_url)
YIELD map
WITH apoc.map.clean(map, [""], []) AS map
MERGE (n:Node {request_id: map.request_id})
SET n += map
Please advise.
11-08-2021 05:21 AM
The request works but the file is no longer accessible. That's why it's not working.
11-08-2021 05:36 AM
I'm sorry, I will repeat myself. Your link is not working that's why the query doesn't work with your link but the query is good. So in order to work, you need to make sure that your file is externally accessible.
11-08-2021 05:48 AM
Weird, but it worked, thanks, your solution is working. Thanks.
All the sessions of the conference are now available online