2
votes

I am new to neo4j and cypher, please let me know if I need to improve my question and I will try to make it more meaningful.

I have a dataset in .csv format conating 1000 rows. I have imported that dataset using cypher in neo4j local host. http://localhost:7474/browser/. Here is the sample dataset image

Transactional data

Columns fromacc and toacc contains repeated values. I want to plot the connected graph having timestamp and amount in the edges and nodes showing fromacc and toacc.

I have attached the image of graph:

connected graph

The query which I have written is:

   LOAD CSV WITH HEADERS FROM "file:///datanew.csv"As row CREATE (demo:demo 
   {blockid:toInteger(row.id),blockhas:row.hash,txnid:row.txs,
   frmacc:row.frmacc,toacc:row.toacc,amount:toInteger(row.amount)})
   Create (p:demo{frm:demo.frmacc})-[r:transferred]- > 
   (q:demo{toa:demo.toacc})  return r

But I am getting only one node connected to another node with repetitions.

Can anyone help me to get the desired graph in image above. Thanks in advance.

Data:

   id   hash    time_stamp  txs from    to  amount
   0    hash1   1231006505  1   685031  97258   65536
   1    hash2   1231469665  1   761055  97260   65536
   2    hash3   1231469744  1   2039922 97261   1000000
   3    hash4   1231470173  1   2271509 584573  3000000
   4    hash5   1231470988  1   2271510 584574  3000000
   5    hash6   1231471428  1   2271511 584577  3000000
   6    hash7   1231471448  2   685031  16785   1000000
   7    hash8   1231471478  1   685031  97258   677888
   8    hash9   1231471498  2   97258   685031  567890
   9    hash0   1231471444  1   97258   584577  100000

Here "from" and "to" represents nodes "A,B" in the the graph I plotted and attached                 
In the vertices amount,timestamp should be mentioned                    
1
I'm confused on your data. You have from and to columns, but where do you create nodes that have some property related to those values so you can look them up later? The standard approach for data import is 1. Create the nodes you need, including with ids or properties corresponding with the relationship creation csv you'll import later. Then 2. Load the relationship import CSV, which has the properties of fields to MATCH to the nodes you previously imported, then you MERGE the relationship between. I think you really need to reread the documentation, including for MERGE and LOAD CSV. - InverseFalcon
Can you clarify whether data exists in your graph before the LOAD CSV (and if so which data)? I also don't understand your usage of :demo nodes, you're creating a demo node with various row data, then also attempting create new :demo nodes that have entirely different data. - InverseFalcon

1 Answers

1
votes

If row.id is the identifier of the relationship between the nodes, then for each row you first need to create a pair of nodes, then create a relationship between them, then set the relationship properties. Use merge instead ofcreate to not create new nodes every time. For example:

UNWIND [{id:0,hash:"hash1",time_stamp:1231006505,txs:1,from:685031,to:97258,amount:65536},
{id:1,hash:"hash2",time_stamp:1231469665,txs:1,from:761055,to:97260,amount:65536},
{id:2,hash:"hash3",time_stamp:1231469744,txs:1,from:2039922,to:97261,amount:1000000},
{id:3,hash:"hash4",time_stamp:1231470173,txs:1,from:2271509,to:584573,amount:3000000},
{id:4,hash:"hash5",time_stamp:1231470988,txs:1,from:2271510,to:584574,amount:3000000},
{id:5,hash:"hash6",time_stamp:1231471428,txs:1,from:2271511,to:584577,amount:3000000},
{id:6,hash:"hash7",time_stamp:1231471448,txs:2,from:685031,to:16785,amount:1000000},
{id:7,hash:"hash8",time_stamp:1231471478,txs:1,from:685031,to:97258,amount:677888},
{id:8,hash:"hash9",time_stamp:1231471498,txs:2,from:97258,to:685031,amount:567890},
{id:9,hash:"hash0",time_stamp:1231471444,txs:1,from:97258,to:584577,amount:100000}] AS row

MERGE (F:demo {id: row.from})
MERGE (T:demo {id: row.to})
MERGE (F)-[r:transferred {id: row.id}]->(T)
SET r.hash = row.hash,
    r.time_stamp = row.time_stamp,
    r.txs = row.txs,
    r.amout = row.amout

RETURN F, T, r