3
$\begingroup$

enter image description here

As you can see from the picture, I want to change the keys names of the list. There are 14314 keys names, but they are all mess, I want to change it with a list of continuous numbers like Range[14314]. But I don't know how to do it.

$\endgroup$
7
$\begingroup$

As an example, we'll use the built-in Titanic dataset

f = ExampleData[{"Dataset", "Titanic"}][GroupBy["class"]];

A Dataset can be converted to an an Association/List form by using the Normal function, e.g.,

Normal[f]

output of Normal[f]

What you want to do is replace the keys and re-convert this into a Dataset, which is easily accomplished by:

With[
 {values = Values@Normal[f],
  newGroups = Range@Length[f]  },
 Dataset@AssociationThread[newGroups, values]]

output of With

$\endgroup$
1
  • $\begingroup$ Thank you very much for helping me solve the problem Mr Schrier! $\endgroup$ – Liming Zhou Mar 20 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.