What do seniors like?
Let's use what we've learned so far to create a summary table, sort for a specific subset of that table, sort the values, and print the most important results. We'll use these techniques to answer the question "what movies do seniors like best?"
Note that in this exercise, we'll group by a list directly in the .groupby() method, as opposed to the video exercise, where we first assigned a list to a variable.
Este ejercicio forma parte del curso
Python for Spreadsheet Users
Instrucciones del ejercicio
- Group by
movie_titleandticket_typeto createmovies_by_ticket_type. - Filter for where
ticket_typeisseniorto createsenior_ticket_movies. - Sort by
ticket_quantityin descending order to createordered_senior_movies. - Print the first 3 rows of
ordered_senior_moviesto the console.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Summarize by movie title and ticket type
movies_by_ticket_type = sales.groupby(____, as_index=False).sum()
# Filter for senior tickets
senior_ticket_movies = movies_by_ticket_type[____[____] == ____].reset_index(drop=True)
# Sort senior ticket sales descending
ordered_senior_movies = senior_ticket_movies.____(____, ascending=____).reset_index(drop=True)
# Print the top 3 rows of the ordered table
____