開始使用免費開始

夏日節奏

在第 1 章中,你發現自 2005 年以來歌曲的平均可舞性一直在上升。現在,你要找出不同月份發行的歌曲,其平均可舞性各是多少。是不是一年中的某些時段會發行更適合跳舞的歌曲?如果你是創作了新舞曲的音樂人,一年當中是否有最佳的發行時機?一起來找答案。

本練習屬於課程

在 Python 中使用 Dask 進行平行程式設計

檢視課程

練習說明

  • 使用 datetime 存取器,從 'release_date' 欄位擷取月份。
  • 選取 'danceability' 欄位,並依月份進行分組。
  • 計算各月份的可舞性平均值。
  • 將結果計算出來。

動手互動練習

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

# Extract the months from the release_date column using its datetime accessor 
months = df['____'].____.____

# Group the danceabilities by month
monthly_groupby = df['____'].____(____)

# Find the mean danceability by month
monthly_danceability = ____

# Compute the result
monthly_danceability_result = ____

monthly_danceability_result.plot()
plt.show()
編輯並執行程式碼