開始使用免費開始

執行 semi join

某些帶來最高收入的曲目來自電視節目,或是其他非音樂類的音訊。你拿到了一張包含最高收入品項的發票表,另外還有一張串流服務中的非音樂曲目表。這題你會用 semi join 找出最高收入的非音樂曲目。

資料表 non_mus_tckstop_invoicesgenres 已為你載入。

本練習屬於課程

使用 pandas 進行資料表連接

檢視課程

練習說明

  • 以內連接將 non_mus_tckstop_invoicestid 合併。將結果存為 tracks_invoices
  • 使用 .isin() 篩選出 non_mus_tckstid 存在於 tracks_invoicestid 欄位者。將結果存為 top_tracks
  • top_tracksgid 分組,並計算 tid 的筆數。將結果存為 cnt_by_gid
  • cnt_by_gidgenres 表依 gid 合併,並印出結果。

動手互動練習

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

# Merge the non_mus_tcks and top_invoices tables on tid
tracks_invoices = ____.merge(____)

# Use .isin() to subset non_mus_tcks to rows with tid in tracks_invoices
top_tracks = _____[non_mus_tcks['tid'].isin(____)]

# Group the top_tracks by gid and count the tid rows
cnt_by_gid = top_tracks.groupby(['gid'], as_index=False).agg({'tid':____})

# Merge the genres table to cnt_by_gid on gid and print
print(____)
編輯並執行程式碼