# Plot 2 columns from a Dataset on the same plot as lists

I have imported as a csv file and converted to a Dataset. I would now like to plot columns of data (by the column title) as ListPlot. I can do this one column at a time, but cannot combine multiple columns.

data = Import["data.csv"];
rest = data[[2 ;;]];
data = Thread[header -> #] & /@ rest // Map[Association] // Dataset


where data is the csv file give by

A,B,C,D
1,2,4,5
5,3,2,5
7,3,8,3
9,8,7,2


I can plot one column as a ListPlot or ListLinePlot, but not two on the same plot (see image). If I simply enter a couple of lists then the ListPlot command works fine. I have tried the command below but get an empty plot as the return

ListLinePlot[{data[[;;,"A"]],data[[;;,"B"]]}]


ETA: The spaces I had in my titles were causing confusion, so I have edited the csv file indicated above to avoid this confusion. To apply bbgodfrey's solution you need to reference the labels from the Dataset (copy and paste avoids any hassles).

• Did this work for you with SPACE between the letter, as you show in the CVS file? or did you remove the space? The example CVS you show has spaces. – Nasser Jan 5 '17 at 5:37
• @Nasser you need to use the headers exactly as they are defined - so if the spaces are preserved when you import you need to use them within the quotation marks. Easiest way (for me) is to copy from the dataset directly - no errors this way. – Esme_ Jan 5 '17 at 23:07
• But that is my question. If you use the CVS file, exactly as show, with the spaces between the letter as you show, then it does not work. i.e. what you show in the code, does not match with what you show in your CVS file. The space should be removed from the CVS files to match what you have. That is what I am saying. – Nasser Jan 5 '17 at 23:28
• @Nasser I'm not understanding what your question is. The reference has to match the label - exactly. If it doesn't it will not work. So if you have trailing spaces preserved in the csv file then yes you will need these in the reference - use copy-paste directly from the Dataset to avoid problems. I created a simple example that mimics the problem I was having for the site - and then applied the solution to my real file and found it worked. I'll edit the question to avoid this confusion for anyone else. – Esme_ Jan 6 '17 at 0:11
• the CVS file you had there before, has SPACE between the letters and the commas. That why you were having the errors. You where using "B" when that is not what the column header were, due to the space. That is all what I am saying. If you try the code, with the space back in there, you'll see it will not work. Any way, not a big deal. Just wanted to point this out. – Nasser Jan 6 '17 at 0:15

Plot all columns with

ListLinePlot[Transpose@data]


or selected columns with, for instance,

ListLinePlot[(Transpose@data)[[{1, 3, 4}]]]


or, equivalently,

ListLinePlot[(Transpose@data)[[{"A", "C", "D"}]]]


• your code for selected columns seems to be missing - thanks for updating – Esme_ Jan 5 '17 at 4:52
• @Esme_ Indeed, it was. Thanks for pointing out the omission. – bbgodfrey Jan 5 '17 at 4:53
• fyi, the code ListLinePlot[(Transpose@data)[[{"A", "C", "D"}]]] does not plot all columns on my version 11.0.1. The other code you show worked ok. Screen shot: !Mathematica graphics – Nasser Jan 5 '17 at 5:06
• @Nasser Very strange. It works fine for me with 11.0.1 on Windows 10 (64 bit). I just reran it to be sure. Here is my screenshot. – bbgodfrey Jan 5 '17 at 5:17
• +1. Equivalently, we can use dataset query syntax, e.g. data[Transpose /* ListLinePlot] or data[Transpose /* ListLinePlot, {"A", "C", "D"}]. – WReach Jan 5 '17 at 16:13
dataset = SemanticImport["data.csv"]


dataset[Transpose /* ListLinePlot]