MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Python for Spreadsheet Users

Lihat Kursus

Petunjuk latihan

  • Group by movie_title and ticket_type to create movies_by_ticket_type.
  • Filter for where ticket_type is senior to create senior_ticket_movies.
  • Sort by ticket_quantity in descending order to create ordered_senior_movies.
  • Print the first 3 rows of ordered_senior_movies to the console.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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
____
Edit dan Jalankan Kode