Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-09-2021 05:16 AM
Hi all, I am loading a csv which looks like this:
When loaded in graph, the 'OTHER_MEDS' column has a datatype of string ofcourse (but in form of a list ie: it looks like a list). I now want that each 'VAERS_ID' node should be mapped to the nodes which are all present in the corresponding 'OTHER_MEDS' column.
For eg:
the node '916623' (of label person) should be mapped to 'wellbutrin', 'vitamin d3', 'zinc sulphate', 'collagen' where all these are 4 different nodes of label medicine. I tried using UNWIND and FOREACH, but was unsuccesful.
Thank you in advance!
Solved! Go to Solution.
08-09-2021 01:54 PM
Hi @Benoit_d , I was able to create the nodes and relationships using these queries:
LOAD CSV WITH HEADERS FROM 'link' AS line
MATCH(adverse_event:Adverse_Event{name:line.VAERS_ID,AE_started_after:toInteger(line.NUMDAYS)})
WITH line.OTHER_MEDS as meds, adverse_event
WITH split(replace(replace(replace(meds,"', '",","),"['",''),"']",''),',') as meds1,adverse_event
UNWIND meds1 as x
MERGE(a:Other_Product{name:x})
CREATE (adverse_event)-[:previous]->(a)
Thank you for your help!
08-09-2021 09:04 AM
Hi Abhisshek,
You have to eliminate the brakets and the apostrophe using regreplace. Then you can use split.
As there is a space between comma and next entry, you might need to remove this space first
with "('levothyroxine', 'phentermine', 'lithium', 'abilify lamictal')" as a
with apoc.text.split(
apoc.text.regreplace (
apoc.text.replace(a, "', '", "','"),
"[()\']",
""),
",") as c
return c
c is then a list.
08-09-2021 10:32 AM
Hi Benoit, thank you for your answer! After obtaining the list, how can I create the nodes from that list? And also, how can I link 'VAERS_ID' to the nodes created through the list?
For the reference, it should look like this:
(will be doing this for every 'VAERS_ID)
08-09-2021 01:54 PM
Hi @Benoit_d , I was able to create the nodes and relationships using these queries:
LOAD CSV WITH HEADERS FROM 'link' AS line
MATCH(adverse_event:Adverse_Event{name:line.VAERS_ID,AE_started_after:toInteger(line.NUMDAYS)})
WITH line.OTHER_MEDS as meds, adverse_event
WITH split(replace(replace(replace(meds,"', '",","),"['",''),"']",''),',') as meds1,adverse_event
UNWIND meds1 as x
MERGE(a:Other_Product{name:x})
CREATE (adverse_event)-[:previous]->(a)
Thank you for your help!
All the sessions of the conference are now available online