시작하기무료로 시작하기

시계열 그래프에 요약 통계 추가하기

pandasmatplotlib API와 table 메서드를 함께 사용하면, 하나의 그래프에 시계열 플롯과 수치 요약을 함께 시각화할 수 있어요:

# DataFrame의 시계열 데이터 그리기
ax = df.plot()

# df DataFrame의 요약 통계 계산
df_summary = df.describe()

# 플롯에 요약 테이블 정보 추가
ax.table(cellText=df_summary.values, 
         colWidths=[0.3]*len(df.columns), 
         rowLabels=df_summary.index, 
         colLabels=df_summary.columns, 
         loc='top')

이 연습은 강의의 일부입니다

Python으로 시계열 데이터 시각화

강의 보기

연습 안내

셸에서 meat_mean을 확인하세요. meat의 모든 시리즈 평균을 담고 있는 DataFrame입니다.

  • meat_mean의 모든 값을 cellText 인자로 지정하세요.
  • meat_mean의 인덱스 값을 rowLabels 인자로 지정하세요.
  • meat_mean의 열 이름을 colLabels 인자로 지정하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Plot the meat data
ax = meat.plot(fontsize=6, linewidth=1)

# Add x-axis labels
ax.set_xlabel('Date', fontsize=6)

# Add summary table information to the plot
ax.table(cellText=meat_mean.____,
         colWidths = [0.15]*len(meat_mean.columns),
         rowLabels=meat_mean.____,
         colLabels=meat_mean.____,
         loc='top')

# Specify the fontsize and location of your legend
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 0.95), ncol=3, fontsize=6)

# Show plot
plt.show()
코드 편집 및 실행