開始使用免費開始

使用 right join 找出熱門片的類型

最受歡迎的電影屬於哪些類型?要回答這個問題,你需要合併 moviesmovie_to_genres 這兩個資料表。在名為 pop_movies 的資料表中,已經從 movies 挑選出前 10 部最受歡迎的電影。為了確保分析涵蓋所有熱門電影,請使用 right join 將它與 movie_to_genres 合併。最後,為完成分析,請統計不同類型的數量。此外,兩個資料表可以用電影的 ID 來合併,但在 pop_movies 中該欄位名為 id,而在 movie_to_genres 中則是 movie_id

pop_moviesmovie_to_genres 資料表已為你載入。

本練習屬於課程

使用 pandas 進行資料表連接

檢視課程

練習說明

  • 使用 right join 合併 movie_to_genrespop_movies。將結果儲存為 genres_movies
  • genre 分組 genres_movies,並計算 id 的筆數。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Use right join to merge the movie_to_genres and pop_movies tables
genres_movies = ____.merge(____, how='____', 
                                      ____, 
                                      ____)

# Count the number of genres
genre_count = genres_movies.groupby('____').agg({'id':'count'})

# Plot a bar chart of the genre_count
genre_count.plot(kind='bar')
plt.show()
編輯並執行程式碼