0
$\begingroup$

I have what it seems to be a very trivial question, but after searching for hours I was not able to find an answer, so I am asking here.

I have an edgelist for a graph, a 2 column csv file with id1,id2 format. I simply want to import it to mathematica and display the graph.

SetDirectory@NotebookDirectory[];
data = Import["net.csv"]

A very large output was generated. Here is a sample of it:
{{1, 11724}, {1, 11725}, {1, 11726}, {1, 11727}, {1, 11728}, {1, 
11729}, {2, 107}, {2, 4050}, {2, 4050}, {2, 4054}, {2, 12202},...

Graph[data]

I get the error massage Mixed graphs and multigraphs are not supported. I really appreciate it if you can guide me here.

I uploaded the csv file here: net.csv.

$\endgroup$
  • $\begingroup$ it will be a great idea to upload your csv file somewhere and place a link here. Probably it's a typing mistake but Graph is the correct command. $\endgroup$ – Raymond Ghaffarian Shirazi Sep 16 '15 at 1:49
  • $\begingroup$ Thanks for the respond. I uploaded the file, added the link to question. $\endgroup$ – Yasmin Sep 16 '15 at 2:04
  • $\begingroup$ It is working fine for me! Are you sure you are opening the right file? Try 'Clear["Global`*"]' at the beginning of your code. $\endgroup$ – Raymond Ghaffarian Shirazi Sep 16 '15 at 2:12
  • $\begingroup$ It didn't change however, PlotGraph worked for me. Could it be a version problem due to this: link I am using mathematica 9 though. $\endgroup$ – Yasmin Sep 16 '15 at 2:20
  • 2
    $\begingroup$ @Yasmin The error message means that you have multiple edges between the same nodes. This is not supported in v9. While v10 will be happy with multi-edges, make sure that this is what you want! Also decide if you want a directed or undirected graph. $\endgroup$ – Szabolcs Sep 16 '15 at 6:03
3
$\begingroup$

Change the data to the edge format can do the work

data = Import["net.csv"]
edges = Map[#[[1]] -> #[[2]]&, data]
Graph[edges]

Which will yield the following result

enter image description here

$\endgroup$
  • 1
    $\begingroup$ It's not necessary to convert the list elements to rules. The reason why it worked for you and didn't work for her is that in version 9 and earlier multiple edges between the same nodes are not supported. Presumably she was using v9 and you are using v10.x. Rules or sublists doesn't make a difference, except that rules automatically create a directed graph. $\endgroup$ – Szabolcs Sep 16 '15 at 6:22
  • $\begingroup$ @Szabolcs Thanks for the clarity. I only have Mathematica version 10. :) $\endgroup$ – m00nlight Sep 16 '15 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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