1
$\begingroup$

I am new to Mathematica, and i am trying to Graph some blockchain transaction data. I would like the Addresses "From" & "To" to be the Nodes/Vertices, and the edges to be a transaction between them "From"->"To", i would also like to have the "Quantity" and "Method" to be the label for the edge. Ideally the graph would be a DirectedGraph. I have imported the CSV data as data1 and it is shown in a Table with the Column names "From", "To", "Quantity",and "Amount". I have tried using Graph[data1], however i get an error saying function expected a graph object at position 1. Any help would be greatly appreciated. Apologies for such a noob question, i have searched far and wide to try find an answer but no luck just yet.

data1 = ResourceFunction["ImportCSVToDataset"]["trimftmdata.csv"];
GraphPlot[data1]

A graph object is expected at position 1 in Graph Plot

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the grey triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – Dunlop
    Commented Oct 22, 2022 at 4:00
  • 1
    $\begingroup$ Hi, it's easier to help when there is a minimal example to work with that one could just copy and paste to their notebook and then show some of the steps with that example. Basically you can either make a toy dataset that mimics the structure of your dataset or you can extract part of the data and copy paste it here. That said, a direct first approach is to use something like Table[DirectedEdge[data[[$LineNumber, 1]], data[[$LineNumber, 2]], {data[[$LineNumber, 3]], data[[$LineNumber, 4]]}], {$LineNumber, $NumberofDataLines}] $\endgroup$ Commented Oct 22, 2022 at 9:43
  • $\begingroup$ line can be replaced with row if you prefer that. The dollar signs are there because using capital letters can lead to conflicts with Mathematica functions but I wanted to highlight the names of the variables. You can use lowercase letters and omit the dollar signs as they are just names I chose. $\endgroup$ Commented Oct 22, 2022 at 9:46

1 Answer 1

0
$\begingroup$

Building on @userrandrand 's answer, define your data, perhaps as

data = {{1, 2, a1, a2}, {1, 3, b1, b2}, {2, 3, c1, c2}};

Then, convert it into a Graph with Tooltipped edges:

Graph@Table[
  Tooltip[DirectedEdge[data[[row, 1]], 
    data[[row, 2]]], {data[[row, 3]], data[[row, 4]]}], {row, 
   Length@data}]

You can improve the presentation of the third and fourth columns by using Style[ToString[...],options about text display].

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.