0

Before

Hi, so I have a dataset structured like this where every row is a team in a race and the score they earned. But I need it shaped like this.

After

It would be better if the scores are added on top of the previous score but that is not a requirement.

Can someone help me? Thanks.

ahmetakil
  • 879
  • 6
  • 15
  • 1
    hey there, more than a reshape this would be called an aggregation, have you looked at using the groupby function by pandas? You're almost certainly looking for df.groupby(['Team','Year']).sum() , i'm sure you can figure out the reshaping to your required format from there – fibonachoceres Oct 11 '20 at 09:32
  • 1
    No images please! And what have you tried? Please see: https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples This will be a `groupby` and then `pivot_table` or `groupby` and then `unstack`. Actually, just a pivot_table! – David Erickson Oct 11 '20 at 09:35
  • Thanks, I solved it by reset_index and then a pivot. also, i won't post an image any more thanks for the warning – ahmetakil Oct 11 '20 at 10:23

0 Answers0