0

I'm trying to calculate the rating difference by gender for each movie. (IMDB dataset)
This is the groupby method i've used:

df.groupby(['movie title', 'gender'])['rating'].mean() 

And the head:

enter image description here

I'd like to create a new dataframe with 2 columns of rating for each movie - for male and female.
For example, the first row will be like:

enter image description here

Thanks!

1 Answer 1

2

You can unstack:

(df.groupby(['movie title', 'gender']) ['rating'].mean() .unstack() .reset_index() # turn `movie_title` into a normal column. ) 

And you should get F,M as column names. Rename as you wish.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.