4
$\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$

1 Answer 1

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$ Commented Mar 20, 2021 at 5:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.