# Plot CSV-data; make statistical statements in Mathematica / WA

First, I'm quite new to Mathematica so sorry in advance if some questions seem to be trivial.

I have a CSV-file which looks like this:

"perc","l1","l2","diff"
0.005,116,148,32
0.005,352,30,322
0.005,249,49,200
0.005,23,336,313
0.0051,130,89,41
0.0051,363,46,317
.
.
.


perc is a percentage between 0…1; l1 and l2 are numbers, diff is the difference between l1 and l2. Those are the first lines; the full set is ~150.000 lines long; with perc from 0 to 1.

I want to plot those data and WolframAlpha (and even GoogleDocs) do a good job here and I get a result like this (actually, this is not entirely correct; perc should be plotted on X, l1, l2 and diff on Y; I hope you know what I mean.  This, however, only works if my CSV is less than ~4000 rows. If it's bigger, WA fails and "does not know how to interpret the data"; same for Google Docs. So, I want to redo this in Mathematica, but I don't know how / it doesn't work.

First, I import my CSV:

data = Import["data.csv", "Table", "HeaderLines" -> 1]

But then I fail with ListPlot because I don't know what options it needs to plot the data correspondingly to WA.

If your data is Imported say in data then you can use data[[All,{1,2}]] to use the first column as x and the second as y value. Plotting all three data sets would be

ListPlot[{data[[All, {1, 2}]], data[[All, {1, 3}]], data[[All, {1, 4}]]}]


If you want to print against row index, like in yopur figure you can use

ListPlot[{data[[All, 2]], data[[All, 3]], data[[All, 4]]}, Frame -> True,
PlotRange -> {0, 1000}, FrameLabel -> {"row index", None}]


Edit:

To make sure that you import the data correctly you have to enforce "CSV" format. Using the "Table" format will give you the following data:

data // FullForm

   List[List["0.005,116,148,32"],List["0.005,352,30,322"],List["0.005,249,49,200"],List["0.005,23,336,313"],List["0.0051,130,89,41"],List["0.0051,363,46,317"]]


As you see each line is interpreted as String. Use

data = Import["data.csv", "CSV", "HeaderLines" -> 1]


data // FullForm


correctly gives a list of numerical list elements and the above ListPlot works.

List[List[0.005,116,148,32],List[0.005,352,30,322],List[0.005,249,49,200],List[0.005,23,336,313],List[0.0051,130,89,41],List[0.0051,363,46,317]]

• Thanks for this, that sounds quite logical :) However, if I try the first command, I get back a Part::partw: Part {1,2} of {0.0053,456,21,435} does not exist. >> followed by the same for 1,3 and 1,4 and a further output stopped. (0.0053,456,21,435 is the first data row) Apr 24, 2012 at 16:06
• Use FullForm[data] to see what is gpoing on. See my edited answer. Apr 24, 2012 at 22:53
• Thanks a lot! Now it works. Great job. Apr 25, 2012 at 6:18

ListPlot requires a list of {x,y} pairs for each data set. What Markus is showing is how to get that in the right format.

For styling, read through the options for PlotStyle and PlotMarkers.

For legends, you have several options:

1. Try to use the PlotLegend Package (bleh)
2. Roll your own with the help of MMA.SE