Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-10-2020 11:21 PM
I have a dataframe in pandas for which i'm trying to create a graph. Here's the data.
**source** **destination** **type**
London New York Arrival
New York Dubai Departure
Manchester Visakhapatnam Departure
New Delhi London Departure
Visakhapatnam Dubai Arrival
I created a list in pandas and got all the unique places into a list like this:
places = ['London', 'New York', .......]
and then converted it into a datafame and created nodes using this query:
def add_unique_places(tx,df_places):
for index,row in df_places.iterrows():
tx.run("""
CREATE (place:P {name: $label1})
""",
parameters={'label1':row['Places']})
Now i divided the data into two dataframes. One for type "Arrival" and one for type "Departure".
All i want now is to create a graph like this:
(London)-[:Arrival]->(New York)
How to achieve this?
PS:
WIthout doing all the above process, i directly took the dataframe and created a graph and merged nodes using apoc. But theres a problem.
Since "London" is in both 'source' and 'destination', it's creating two different nodes but i only want one node.
Thank You!
Peace!
Solved! Go to Solution.
03-10-2020 11:58 PM
Sorry, I did not understand your requirement completely.
However with my best understanding with the dataframe you have given try below
load csv with headers from 'file:///travel.csv' as line
Merge(n:Place{name:line.source}) Merge(m:Place{name:line.destination}) Merge (n)-[:TRAVEL_TYPE{type:line.type}]->(m)
03-10-2020 11:58 PM
Sorry, I did not understand your requirement completely.
However with my best understanding with the dataframe you have given try below
load csv with headers from 'file:///travel.csv' as line
Merge(n:Place{name:line.source}) Merge(m:Place{name:line.destination}) Merge (n)-[:TRAVEL_TYPE{type:line.type}]->(m)
03-11-2020 12:16 AM
I think it's doing the work. Thank you vivek!
03-11-2020 02:06 AM
Also, i have one more question.
Suppose i have two relations like this:
(london)-[:DEPARTURE{time:10:30}]->(newYork)
(vizag)-[:ARRIVAL{time:10:30}]->(Delhi)
Now i want all nodes with time:10:30 whether the relation is "ARRIVAL" or "DEPARTURE".
what is the query for this? Thank you.
Peace
03-11-2020 02:18 AM
(n)-[rel:ARRIVAL|:DEPARTURE]->(m) Where rel.time='10:30' Return n,rel,m
All the sessions of the conference are now available online