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
However, I can't get it to work with SemanticImport
.
I can use the following code, but hoped SemanticImport
would basically replace this:
Import["testdata.csv"];
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];
Dataset[testFullAss]
Answer
Using
SemanticImport["testdata.csv"]
I get
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}};
Then:
Dataset[AssociationThread[First @ data, #] & /@ Rest @ data]
Comments
Post a Comment