-1

I have a dataframeData I need it to look like

playerID  Pts_1 Pts_2 Pts_3 Pts_4 Pts_5 

adamsst01 1108  684  438    528   361

using python/pandas if anyone can help me please. I want to use the unique playerIDs to collate all their points

I tried to use pivot but that gave an error, ValueError: Index contains duplicate entries, cannot reshape.

I tried transpose but that gives the wrong shape, just wider.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
Dj22
  • 1
  • 2
  • Are there exactly 5 points for each player? – Tim Roberts Aug 21 '23 at 00:55
  • Question 10 in the dupe is the relevant one, you just need to adapt it slightly: `df.pivot_table(index=df.groupby('playerID').cumcount(), values='PTS', columns='playerID').T.add_prefix('pts_').reset_index()` – Nick Aug 21 '23 at 01:13

0 Answers0