# Reading csv/xlsx data into Mathematica with column headings as list names

It's old question. However, I could not find satisfactory answer. Decided to post this question. I have a .csv file with column heading. How can I import this .csv file into Mathematica assigning column names as list names in short and sweet way. For example, I can use the following codes.

mydata = Import[file, Path -> path];
names = Flatten[mydata[[;; 1]]];
Do[listnames[names[[i]]] =
mydata[[2 ;;]][[All, i]], {i, 1, Dimensions[mydata[[2 ;;]]][[2]]}];


But I need to write listnames["Col names in .csv file"] to refer to each list. I can not refer .csv column names as list names. I need to figure out this because I have over 1000 column headings in my .csv data. Please help me to figure out his without long codes.

-

Update

Inspired by Andy Ross

data = Rest @ iris;

assign[name_, value_] := Evaluate[ToExpression[name]] = value;

====================================================================

If you are using Mathematica 10, there is a new data type called Dataset. Take the iris data for example. Suppose the iris.csv is in d:\.

iris = Import["d:/iris.csv","CSV"];

data = iris[[2;;]];



and it will display like this:

-
Thank you for your time. Yes, I am using Mathematica 10. I tried your codes but it does not give me the results I desire. I want the column names of .csv file as list names so that I can refer each .csv column data by their column name as list name in Mathematica. In your example, I should be able to refer each column as a separate list with its name being column heading. I should be able to refer first column as a list as Sepal.Length, second column as another list as Sepal.Width and so on.... –  ramesh Aug 12 '14 at 0:54
@rkadhikari I advise reading the documentation page for Dataset -- it's pretty trivial to take a dataset and extract the raw columns from it, but you might find the Dataset itself much easier to work with for some kinds of things. –  Taliesin Beynon Aug 12 '14 at 2:33
Thanks for your time, PhilChang. That's what I was looking for. You are really genius!!:) –  ramesh Aug 12 '14 at 2:34
@PhilChang SemanticImport makes it really easy to import a tabular file as a Dataset if they have a reasonable structure -- no need to parse it to and format it yourself. So for example your code could just be replaced with SemanticImport["https://raw.githubusercontent.com/pydata/pandas/master/pandas/t‌​ests/data/iris.csv"] –  Taliesin Beynon Aug 12 '14 at 2:36
An alternative way to create a Dataset is irisDataset = Dataset[Inner[Rule, header, Transpose[data], Association]]. –  Ernst Stelzer Aug 12 '14 at 7:38