After some calculations and a GroupBy
I have a Dataset
that is structured like this.
dat = Dataset@<|
"Apples" ->
ConstantArray[Graphics[{Red, Rectangle[]}, ImageSize -> {300, Automatic}], 3],
"Oranges" ->
ConstantArray[Graphics[{Orange, Rectangle[]}, ImageSize -> {300, Automatic}],
2],
"Bananas" ->
ConstantArray[Graphics[{Yellow, Rectangle[]}, ImageSize -> {300, Automatic}], 5]
|>
I now would like to apply a function to each of these rows that uses the row name in first row for for a Grid
. However, I have been unable to figure out how to reference the row name using the dataset[All, f] query syntax as provided in the Dataset | Dataset Queries documentation.
I can do the Grid
without the row name with:
dat[All, Grid[Partition[#, 2, 2, {1, 1}, ""]] &]
How do I reference the row name in the function? Is there some syntax of Keys
that I should be using? I think not as Keys
would give me the keys of the row columns. I'm looking for some sort of ParentKey
function such that I could get the row's key for the grid. e.g.
dat[All,
Grid[
Join[
{{ParentKey@#, SpanFromLeft}},
Partition[#, 2, 2, {1, 1}, ""]
]] &]
Grid
code (becauseDataset
), just FYI. $\endgroup$dat[KeyTake["Apples"], All]
? $\endgroup$dat[Grid@Transpose@{Keys@#, Values@#} &]
? $\endgroup$