Getting Ratings by Gender

Learn how to use the functions in Python that reshape a data set.

To get the ratings by size, look at line 19 of the code widget below.

We want to avoid movies that don’t have many reviews as that would skew our data. So we’re only selecting movies that have at least 250 reviews. This is an arbitrary number and will help us filter out only popular movies.

The next feature is very powerful. Say we want to reshape a data set. We could perform multiple select and join operations. But the pivot_table() function makes it simple for us. Here, we want to create a new table that has ratings of the movies selected by different genders.

Line 21 of the code widget does exactly that.

The pivot_table() takes the movie_data and reshapes it. The three arguments are as follows:

  1. Arrange the data by rating.

  2. The index should be the title.

  3. The columns should be based on represented genders.

Let’s see what we get:

Get hands-on with 1200+ tech skills courses.