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.

Merge on null

Hello everyone
I am interacting with neo4j using python with cypher . I have an excel sheet with an uneven number of colum information eg
column Colour: Red,Green,Yellow
column Car: Corolla,Camry,lexus
column Animal: dog,cat,fish,antelope,camel,pidgeon

as a result of column animal having more column info whenever i run my merge command,null nodes are created on column colour and car since they are both short of 3 column data. I have tried running the foreach (ignoreme) command yet null values are still created. I want just 12 nodes created not 14 as the 2 extra are as a result of null values.

for record in data:
colour = record[0]
car= record[1]
animal = record[2]
query = """
Merge(Info:data{colour:{a}})
SET Info.car={b}
SET Info.Animal={c}
MERGE(Animalt:Animal{Animal:{c}})
FOREACH(ignoreMe IN CASE WHEN {colourt:{a}} IS NOT NULL THEN [1] ELSE END |
MERGE(colourt:colour{colour:{a}})
MERGE (colour)-[:Relevance]->(Animal))
"""
how do i go about solving this?

1 REPLY 1

ameyasoft
Graph Maven
Try this:

LOAD CSV WITH HEADERS FROM "file:/olojo.csv" AS row
with row

FOREACH(ignoreMe IN CASE WHEN row.Color IS NOT NULL THEN [1] ELSE [] END |

MERGE (color:Color {color: row.Color})

)

FOREACH(ignoreMe IN CASE WHEN row.Car IS NOT NULL THEN [1] ELSE [] END |

MERGE (car:Car {car: row.Car})

)

FOREACH(ignoreMe IN CASE WHEN row.Animal IS NOT NULL THEN [1] ELSE [] END |

MERGE (animal:Animal {animal: row.Animal})

);

Added 12 labels, created 12 nodes, set 12 properties, completed after 167 ms.

Result:
2X_b_b73478d2ade4696442eada8065208e814792cb27.png