0

In Python imagine I have this as my dataframe, a list of songs and their groups

Song Title Category
Hello Pop
Night Fever Rock
Dancing Pop
My Star Metal

I want to be able to transform all the values under "category" into a new dataframe, so the values are columns, and under each column, it lists the songs. See below for desired outcome...

Pop Rock Metal
Hello Night Fever My Star
Dancing

I'm sure theres a simple code for this in either pyhton or pandas, any help would be appreciated.

Thanks

  • 1
    This is pivot: `df.assign(index=df.groupby("Category").cumcount()).pivot("index","Category","SongTitle")` as mentioned in the duplicate link – anky Dec 15 '21 at 12:27
  • 1
    Thank you, I couldn't find this earlier but this has work :) – VCMolly Dec 15 '21 at 12:41

0 Answers0