开始使用免费开始使用

执行半连接(semi join)

收入最高的一些曲目来自电视节目或其他非音乐音频。您拿到了一张包含高收入条目的发票表。同时,还有一张来自流媒体服务的非音乐曲目表。在本练习中,您将使用半连接来找出带来最高收入的非音乐曲目。

non_mus_tckstop_invoicesgenres 已为您加载。

本练习是课程的一部分

使用 pandas 连接数据

查看课程

练习说明

  • 使用内连接在 tid 上合并 non_mus_tckstop_invoices。将结果保存为 tracks_invoices
  • 使用 .isin() 筛选 non_mus_tcks 中那些 tid 出现在 tracks_invoicestid 列中的行。将结果保存为 top_tracks
  • gidtop_tracks 分组,并统计 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(____)
编辑并运行代码