BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Python for Spreadsheet Users

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Use .groupby() and .sum() to create a summary table by theater_location and movie_title.
  • Sort totals by ticket_quantity in descending order.
  • Use .groupby() and .head() to extract the top movie by theater_location.
  • Print top_movies.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# 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
____
Kodu Düzenle ve Çalıştır