0

I have a dataframe indexed by Race_ID which records a column Win_prob_entropy and it looks like

Race_ID Win_prob_entropy
1       0.035133431
1       0.18972781
1       0.529570381
1       0.022403749
1       0.211830728
1       0.296955621
1       0.252448331
1       0.265546633
1       0.324423637
1       0.029776935
1       0.331058118
1       0.375
1       0.157954935
1       0.079024101
2       0.031153301
2       0.038599179
2       0.031396277
2       0.057557422
2       0.526982765
2       0.024338669
2       0.066124977
2       0.230143351
2       0.5
2       0.039996297
2       0.318073588
2       0.117677496
2       0.36636341
2       0.142571676

and I want to create a new column called Race_entropy, which should be easy and goes like

df['Race_entropy'] = df.groupby('Race_ID')['Win_prob_entropy].sum()

However, it outcomes gibberish like

Race_ID Win_prob_entropy    Race_entropy
1   0.035133431 
1   0.18972781  
1   0.529570381 3.20080115
1   0.022403749 
1   0.211830728 2.96402698
1   0.296955621 2.9217451
1   0.252448331 3.05528643
1   0.265546633 3.16719348
1   0.324423637 
1   0.029776935 2.68081565
1   0.331058118 2.92047075
1   0.375   3.31699119
1   0.157954935 3.21470452
1   0.079024101 
2   0.031153301 3.16268324
2   0.038599179 
2   0.031396277 
2   0.057557422 3.50547874
2   0.526982765 3.10773035
2   0.024338669 
2   0.066124977 
2   0.230143351 3.00149541
2   0.5 3.03232797
2   0.039996297 3.21332968
2   0.318073588 2.98780622
2   0.117677496 
2   0.36636341  3.65646916
2   0.142571676 

I tried to google a bit and most problems have to do with datatype so I checked mine and the dtype for Race_ID is int and that of Win_prob_entropy is float. I have no idea why it doesn't work. Here is a snapshot of the dataframe: enter image description here Thank you so much for your help.

Nayr borcherds
  • 395
  • 1
  • 6

0 Answers0