MSD 汇总统计
先熟悉一下 Million Songs Echo Nest Taste Profile 的数据子集。在本课程中,我们将其简称为 Million Songs 数据集或 msd。请获取用户数量和歌曲数量。还要查看在这个子集中哪些歌曲的播放次数最多。
本练习是课程的一部分
使用 PySpark 构建推荐引擎
练习说明
- 使用
.show()方法查看数据的基本结构。 - 完成代码以统计不同
userId的数量。先选择userId列,然后依次调用.distinct()和.count()。 - 对
songId做同样的操作,统计不同songId的数量。选择songId列并调用.distinct()和.count()。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Look at the data
msd.____()
# Count the number of distinct userIds
user_count = msd.select("____").____().count()
print("Number of users: ", user_count)
# Count the number of distinct songIds
song_count = msd.select("____").____().count()
print("Number of songs: ", song_count)