MSD 摘要統計
先來熟悉一下 Million Songs 的 Echo Nest Taste Profile 子集。在本課程中,我們會簡稱為 Million Songs 資料集或 msd。先取得使用者數量與歌曲數量,並查看在這個子集中哪些歌曲的播放次數最多。
本練習屬於課程
使用 PySpark 打造推薦引擎
練習說明
- 使用
.show()方法查看資料的樣子。 - 完成程式碼以計算不同
userId的數量。先選取userId欄位,接著呼叫.distinct()與.count()。 - 用相同方式計算不同
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)