Best-selling movie by location
With our new tools, we can create even more useful tables. Recall earlier, when we found the best-selling movie in Portland - we had to filter our table for Portland films only, then sort the values to find our best-seller. It would be pretty time consuming to do this for every theater location.
Instead, using some of our new tools, we can quickly condense our sales transaction data down to a summary table, sort that summary table, and get the top movie for each market all at once.
Este ejercicio forma parte del curso
Python for Spreadsheet Users
Instrucciones del ejercicio
- Use
.groupby()and.sum()to create a summary table bytheater_locationandmovie_title. - Sort
totalsbyticket_quantityin descending order. - Use
.groupby()and.head()to extract the top movie bytheater_location. - Print
top_movies.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Create a summary by theater location and movie title
totals = sales.____([____, ____], as_index=False).____()
# Sort totals by ticket quantity in descending order
totals_sorted = totals.____(____, ascending=False).reset_index(drop=True)
# Take the top row for each theater location
top_movies = totals_sorted.____(____).____(1).reset_index(drop=True)
# Print results
____