0
votes

I have two csv files: (clean_data_2.csv : Sample Content as under)

enter image description here

(stationdata.csv : Sample Content as under)

enter image description here

From my cypher query, I want that each station is represented as node and relationship is represented as count.

I did something like this:

USING PERIODIC COMMIT 
LOAD CSV WITH HEADERS FROM "file:///stationdata.csv" AS line
CREATE (s:station{id:line.station_id,station_name:line.name});

Loading all station data: it creates all the nodes - source and destination columns

LOAD CSV WITH HEADERS FROM "file:///clean_data_2.csv" AS line
MATCH (src:station),(dst:station)
CREATE (src)-[:TO{ count: [line.count]}]->(dst);

The above part runs, but does not give me count in the relationship between nodes.

I am new to Neo4j - graph databases, thanks!

1
Can you show in your question the actual contents of the 2 CSV files?cybersam
Hi @cybersam: I have added snippets :)Pratyush Kulwal
That is a bit better, but can you show snippets of the raw data -- not whatever is displayed by a tool (like a spreadsheet app)? Also, please delete the original tabular data, as that is incorrect.cybersam
Also, one glaring issue is that your second query's MATCH clause does not specify the names of the station nodes for src and dst, so all possible pairs of station nodes will be matched. That should cause the creation of a lot of extra TO relationships with count properties, and yet you seem to be saying that you don't get any count properties?cybersam
@cybersam: Yeah, exactly! I am getting extra relationships, and I am not able to figure it out, how to specifiy names for src and dst nodes. Apologies, my question was not clear :)Pratyush Kulwal

1 Answers

2
votes

Your second query's MATCH clause does not specify the names of the station nodes for src and dst, so all possible pairs of station nodes would be matched. That would cause the creation of a lot of extra TO relationships with count properties.

Try using this instead of your second query:

LOAD CSV WITH HEADERS FROM "file:///clean_data_2.csv" AS line
MATCH (src:station {name: line.src}), (dst:station {name: line.dst})
CREATE (src)-[:TO {count: TOINTEGER(line.count)}]->(dst);

This query specifies the station names in the MATCH clause, which your query was not doing.

This query also converts the line.count value from a string (which all values produced by LOAD CSV are) into an integer, and assigns it as a scalar value to the count property, as there does not seem a need for it to be an array.