绘制平均频率
最后,我们将按天计算两个话题标签的平均提及次数,并将其随时间绘制出来。我们会先按天把两个布尔 Series 转换成比例,然后再绘图。
matplotlib.pyplot 已以 plt 导入,ds_tweets 也已为您加载。
本练习是课程的一部分
在 Python 中分析社交媒体数据
练习说明
- 使用
.resample()和.mean()方法,对python列生成推文的平均数。.resample()只需传入一个参数'1 d',即可得到按天的平均值。 - 对
rstats列执行相同操作。 - 使用
mean_python绘制#python的折线图。用mean_python.index.day作为 x 轴。 - 对
mean_rstats执行相同操作。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Average of python column by day
mean_python = ____[____].____(____).____()
# Average of rstats column by day
mean_rstats = ____[____].____(____).____()
# Plot mean python by day(green)/mean rstats by day(blue)
plt.plot(____, ____, color = 'green')
plt.plot(____, ____, ____)
# Add labels and show
plt.xlabel('Day'); plt.ylabel('Frequency')
plt.title('Language mentions over time')
plt.legend(('#python', '#rstats'))
plt.show()