I might use this incorrectly. I want to use a .csv file that (as list) looks like:

{{"Group", "data 1", "data 2"}, {"a", 1, 5}, {"a", 2, 3}, {"a", 4, 5}, {"b", 8, 9}}

Now I want this as a Dataset, i.e. I try and import it with SemanticImport and would want to have as result

enter image description here

However, I can't get it to work with SemanticImport.

I can use the following code, but hoped SemanticImport would basically replace this:

dataDim = Dimensions@data;
a1 = Transpose@
   Table[data[[1, i]] -> data[[1 + j, i]], {i, dataDim[[2]]}, {j, 
     dataDim[[1]] - 1}];
testFullAss = Association[a1[[#]]] & /@ Range[dataDim[[1]] - 1];

  • $\begingroup$ If you can tell me how I can add a file to my question I will do. But basically, if you Export the list at the beginning at my question as a .csv file, you'll have the file. $\endgroup$ Commented Sep 14, 2014 at 17:32

1 Answer 1




I get

Mathematica graphics

on the exported data you provided which is the dataset you seek. But SemanticImport has been reported to have a few bugs, maybe that's why you can't get it to work. In the meantime, and in between time, you can use the much cleaner approach to obtain your dataset after using Import on your file:

data = {{"Group", "data 1", "data 2"}, {"a", 1, 5}, {"a", 2, 3}, {"a", 4,  5}, {"b", 8, 9}};


Dataset[AssociationThread[First @ data, #] & /@ Rest @ data]

Mathematica graphics

  • $\begingroup$ OK, that's weird you get the correct result. But at least it in principle appears to work. Thanks for the much shorter code you provided, which I will use in the meantime. $\endgroup$ Commented Sep 14, 2014 at 17:50
  • $\begingroup$ @MockupDungeon. You're welcome :) $\endgroup$
    – RunnyKine
    Commented Sep 14, 2014 at 17:51
  • $\begingroup$ Setting dset = Dataset[AssociationThread[First @ data, #] & /@ Rest @ data] and din = SemanticImport["data.csv"], note that dset === din gives False, because as the FullForms reveal, they have different values for Association[Rule["ID".... What's the best way to extract just the datasets, without their IDs, so as to be able to compare? $\endgroup$
    – murray
    Commented Sep 14, 2014 at 18:59
  • $\begingroup$ @murray, that's a good observation. I hadn't noticed that. I'll look into it. $\endgroup$
    – RunnyKine
    Commented Sep 14, 2014 at 19:29
  • $\begingroup$ @murray, One way will be to do Normal[dset] == Normal[din] which yields True as expected. $\endgroup$
    – RunnyKine
    Commented Sep 14, 2014 at 19:30

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.