I'd like to create a Dataset from an array, where each column's heading becomes the key for all elements in that column. I can accomplish this using nested Table commands, but was wondering if there is a more elegant way that directly leverages the syntax developed for Datasets. E.g., could this instead be accomplished using GroupBy?:
list = {{"date", "time", "volume"}, {a1, a2, a3}, {b1, b2, b3}, {c1,
c2, c3}}
Table[<|Table[
list[[1, i]] -> list[[n, i]], {i, 1, Length@list[[1]]}]|>,
{n, 2, Length@list}]
Dataset@%
AssociationThread[{"date", "time", "volume"} -> {{a1, a2, a2}, {b1, b2, b3}, {c1, c2, c3}}]
$\endgroup$Dataset@AssociationThread[{"date", "time", "volume"} -> {{{a1, a2, a2}}, {{b1, b2, b3}}, {{c1, c2, c3}}}]
? Sorry, I'm away from Mathematica at the minute :) (Related: mathematica.stackexchange.com/questions/246088/…) $\endgroup$Rest@list
, restructuring it from{{a1, a2, a3}, {b1, b2, b3}, {c1, c2, c3}}
to{{{a1, a2, a3}}, {{b1, b2, b3}}, {{c1, c2, c3}}}
. I could do that, but then I'm back to using Table. I triedPartition
, but it only adds an extra set of braces on the outside:Partition[Rest@list, 3]
=>{{{a1, a2, a3}, {b1, b2, b3}, {c1, c2, c3}}}
$\endgroup$