Using the example in the documentation, how would I make a new dataset with the key "b" changed to key "h".
dataset = Dataset[{
<|"a" -> 1, "b" -> "x", "c" -> {1}|>,
<|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,
<|"a" -> 3, "b" -> "z", "c" -> {3}|>,
<|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>,
<|"a" -> 5, "b" -> "y", "c" -> {5, 6, 7}|>,
<|"a" -> 6, "b" -> "z", "c" -> {}|>}]
I tried:
dataset /. "b"-> "h"
and also
Normal[dataset] /. "b"-> "h"
Which don't work. This comes up when I get sums using GroupBy
. I'm using code from Szabolcs which results in my getting the sums, but they have the same name as the original key. I still don't really understand the code I'm using so I don't know how to handle it there, if possible. Eventually I have to use a JoinAcross
to merge these totals with the original detail, and I need separate key names.
Szabolcs code is:
sales[
GroupBy[#, KeyTake[{"Country", "Region", "BU", "Year"}] -> KeyTake["Sales"], Total] &
][Normal
][All, Apply[Join]]