Plotting mean frequency
Lastly, we'll create a per-day average of the mentions of both hashtags and plot them across time. We'll first create proportions from the two boolean Series by the day, then we'll plot them.
matplotlib.pyplot has been imported as plt and ds_tweets has been loaded for you.
Bài tập này là một phần của khóa học
Analyzing Social Media Data in Python
Hướng dẫn bài tập
- Generate the mean number of tweets with the
pythoncolumn with.resample()and.mean()methods..resample()takes one argument,'1 d', to produce daily averages. - Do the same with the
rstatscolumn. - Plot a line for
#pythonusage withmean_python. Usemean_python.index.dayas the x-axis. - Do the same with
mean_rstats.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# 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()