夏日律动
在第 1 章中,您发现自 2005 年以来歌曲的平均可舞性在上升。现在,请找出不同月份发行歌曲的平均可舞性。是否一年中的某个时期会发布更适合跳舞的歌曲?如果您是一位创作了新舞曲的音乐人,一年里是否有最佳的发行时机?让我们来找一找答案。
本练习是课程的一部分
Python 中的 Dask 并行编程
练习说明
- 使用 datetime 访问器从
'release_date'列中选取月份。 - 选取
'danceability'列,并按月份进行分组。 - 计算各月份的可舞性均值。
- 计算结果(compute)。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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()