從 Parquet 讀取 Dask DataFrame
在第 1 章中,你分析了部分 Spotify 資料,這些資料分散在多個檔案中,用來找出 2005–2020 年的熱門歌曲。你當時使用 dask.delayed() 搭配迴圈完成。現在我們來看看,使用 Dask DataFrame 後,這項分析能變得多麼簡單。
dask.dataframe 已經替你匯入為 dd。
本練習屬於課程
在 Python 中使用 Dask 進行平行程式設計
練習說明
- 載入位於
"data/spotify_parquet"的 Parquet 資料夾。 - 使用 DataFrame 的
.nlargest()方法,依'popularity'找出前 10 首歌曲。 - 將延遲物件計算為 pandas DataFrame。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Read the spotify_parquet folder
df = ____
# Find the 10 most popular songs
top_10_songs = ____
# Convert the delayed result to a pandas DataFrame
top_10_songs_df = ____
print(top_10_songs_df)