-1

Hi I have this dictionary

df = 
{
1: 0.03287410711253387, 
2: 0.1110746346378032, 
3: 0.23769202033121095, 
4: 0.6183592379186247
}

I'd like to replace the 1,2,3,4 with A,B,C,D

I have tried

df['A','B','C','D'] = df.pop[1,2,3,4]

it gives me this error

ValueError: Length mismatch: Expected axis has 414 elements, new values have 4 elements

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Youssef
  • 565
  • 1
  • 5
  • 21
  • I am working with a large data frame, sorry I didn't write this question the right way – Youssef Jul 14 '22 at 23:55
  • 1
    Does this answer your question? [Change the name of a key in dictionary](https://stackoverflow.com/questions/4406501/change-the-name-of-a-key-in-dictionary) – AboAmmar Jul 15 '22 at 00:13

1 Answers1

1

I don't know why it's tagged pandas but you can do:

dict(zip(['A','B','C','D'], df.values()))