How to Split a ROW into two labels or nodes while importing CSV file

Hi,

I would like to Split a row into two labels while importing the data with CSV. Whereas manufacturer node is already created and the split action will be done to connect a relationship between manufacturer and vehicle type.

mochalla_2-1663663916686.png

I am trying something like this:

mochalla_1-1663663887923.png

Hi I'm not sure I understand your problem

I'm assuming you want to MATCH the first column with your existing manufacturer and then CREATE a Vehicle Type and also a relationship with it

WITH [["JEA1_Z21", "Bulker"], ["KLQ2_Z34", "Truck"]] as rows // you should change this to your LOAD CSV....
UNWIND rows AS row

WITH
row[0] AS manufacturer,
row[1] AS vehicleType

MATCH (m: Manufacturer { id: manufacturer})
WITH m, vehicleType

MERGE (v:VehicleType {id: vehicleType})
MERGE (m)-[:LOADS]->(v)

Try this:

LOAD CSV WITH HEADERS FROM 'file:///xxx.csv' AS row

WITH row, row.` Manufacturer and Vehicle Type` as mvt
WITH row, split(mvt, "_") as mvt2

MERGE (a:Manufacturer {name: mvt2[0]})
MERGE (b:VehicleType {vehicle: mvt2[1], type: row.` Vehicle Type` })
MERGE (a)-[:LOADS]->(b)

Hi @mochalla !

If I understand correctly you could try to do something like:

LOAD CSV FROM 'file:///file.csv' AS row
MERGE (v:Vehicle {type: row[1]})
MERGE (m:Manufacturer {code: row[0]})

MERGE (m)-[:LOADS]->(v) 

You just have to move the file.csv (of course this would depend on your file name) with your data into the import folder of your Neo4j installation, if you are using Neo4j Desktop it should be accessible through the DBMS options menu.

Hope this helps!