I am trying to read the csv file which have nodes ids and their respective relation between them. First two columns represent nodes and third colum represents the relation between them. So far I am able to create the database in neo4j but I am not sure what would be the cypher query to fetch the desired data into pandas DataFrame!
I will use the subset of large dataset here to illustrate my problem. Original dataset contains thousands of nodes and relations.
My csv file(Node1_id, Node2_id, relation_id) looks like this:
0 1 1
4 2 1
44 3 1
0 4 1
0 5 1
4 10173 3
4 10191 2
4 10192 2
6 10193 2
8 10194 2
3 10195 2
6 10196 2
Here is the nodes creation and defining the relation between the nodes by loading the ids from a csv file. (I suppose this graph is correct but let me know if you notice any problem ) I am assigning one property "id" for nodes and relation using their ids from the csv file.
LOAD CSV WITH HEADERS FROM 'file:///edges.csv' AS row FIELDTERMINATOR ","
WITH row
WHERE row.relation_id = '1'
MERGE (paper:Paper{id:(row.Node1_id)})
MERGE (author:Author{id:(row.Node2_id)})
CREATE (paper)-[au:AUTHORED{id: '1'}]->(author);
So far i have tried something like this:
query = ''' MATCH (paper)-[au:AUTHORED{id: '1'}]->(author) RETURN paper,author LIMIT 3; '''
result = session.run(query)
df = DataFrame(result)
for dataF in df.itertuples(index=False):
print(row)
It returns this:
0 1
0 (id) (id)
1 (id) (id)
2 (id) (id)
Desired results:
I want results into pandas DataFrame in the format with nodes ids and relation ids such as defined in csv above by querying the data from graphDB and iterate the results row by row.
0 1 1
4 2 1
44 3 1
0 4 1
0 5 1
4 10173 3
4 10191 2
4 10192 2
6 10193 2
8 10194 2
3 10195 2
6 10196 2
I am also interested into know what is the return type of an cypher query object in this case it is pandas.core.frame.DataFrame
but how can I access the induvial properties of nodes and relation during the cypher query. This is the main problem.
Please feel free to explain in detail, I would really appreciate the help.
Using neo4j Version: 4.2.1