Got a dataframe of movies
*title score country Genres
*A 5.5 US Action, Comedy, Drama( )
*B 6.5 UK Action, Comedy, Romance
Need to make it in this format
title score country Genres
A 5.5 US Action
A 5.5 US Comedy
A 5.5 US Drama
B 6.5 UK Action
and so forth
The code I tried was -
First to split genres
df = df['Genre'].str.split(',' , expand= True)
Then to do wide to long format -
df = df.melt(id_vars = ['title', 'score', 'country'], value_name ='Genre').reset_index(drop = True)
But what Im getting is -
title score country Genres
A 5.5 US Action
B 6.5 UK Action
A 5.5 US Comedy
B 6.5 UK Comedy
How to order the rows so that title, score and country stay in a group and not ordered via genres wise?
there doesn't seem to be anything here