평균 빈도 그리기
마지막으로, 두 해시태그가 언급된 횟수의 일별 평균을 만들고 시간에 따라 시각화해 보겠습니다. 먼저, 두 개의 불리언 Series에서 일별 비율을 만든 다음 이를 그래프로 그릴 거예요.
matplotlib.pyplot은 plt로 임포트되어 있고, ds_tweets는 이미 로드되어 있어요.
이 연습은 강의의 일부입니다
Python으로 소셜 미디어 데이터 분석하기
연습 안내
.resample()과.mean()메서드를 사용해python열의 트윗 평균을 생성하세요. 일별 평균을 만들기 위해.resample()에는 인수로'1 d'를 넣습니다.rstats열에도 동일하게 적용하세요.#python사용량은mean_python으로 선 그래프를 그리되, x축은mean_python.index.day를 사용하세요.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()