# 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;;]];


@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 at 2:33
@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 at 2:36
An alternative way to create a Dataset is irisDataset = Dataset[Inner[Rule, header, Transpose[data], Association]]. –  Ernst Stelzer Aug 12 at 7:38