2
$\begingroup$

I am reading in some data from a CSV file that has a line which gives titles to each "column".

Here is an example:

Entry No,Val1,Val2,Val3,Val4
0,1.01,1.345,5.234,345.45
1,2.456,1.256,250.56,45.027

In reality this file has 20 or so values on each line, and therefore 20 column titles on the first line. I want to display this data in a table, so I first import the file and then display it like so:

dataSet1 = Take[Import["data_set_1.csv","CSV","HeaderLines"->1]] 
TableForm[dataSet1]

I want to be able to manipulate and plot my data later so I am pretty sure I have to remove the line containing the labels using the "Headerlines->1" option.

I would like the table to display the column titles that were on he first line of the CSV file. I know that I could specify them manually, but I think there should be someway to do this because I deleted them the set using "HeaderLines"

$\endgroup$
1

1 Answer 1

3
$\begingroup$
data= Import["http://pastebin.com/raw.php?i=7jJ4e2jW"];
titles = First@data; data = Rest@data;
TableForm[data, TableHeadings -> {None, titles}]
(*Displays the Table *)
(*Do Something with Data*)
ArrayPlot[data] 

enter image description here

$\endgroup$
3
  • $\begingroup$ thank you for your answer. I was actually asking about putting the titles on the table not on a plot. Also I tried to use your method of first and rest but It gave me errors. $\endgroup$
    – Ajay
    Commented Jul 25, 2014 at 19:29
  • $\begingroup$ @Ajay This answer works perfectly with me. It also produces a table with the desired headings. $\endgroup$
    – eldo
    Commented Jul 25, 2014 at 20:50
  • $\begingroup$ @eldo The answer has been edited since I tried to get that to run I for got that I needed to put None as the row labels in the table. $\endgroup$
    – Ajay
    Commented Jul 25, 2014 at 21:05

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.