1. Learn
  2. /
  3. 课程
  4. /
  5. 用 Python 可视化时间序列数据

Connected

道练习

为时间序列图添加汇总统计

通过结合使用 pandas 提供给 matplotlib 的 API 和 table 方法,您可以在同一张图上同时展示时间序列曲线和数值汇总信息:

# Plot the time series data in the DataFrame
ax = df.plot()

# Compute summary statistics of the df DataFrame
df_summary = df.describe()

# Add summary table information to the plot
ax.table(cellText=df_summary.values, 
         colWidths=[0.3]*len(df.columns), 
         rowLabels=df_summary.index, 
         colLabels=df_summary.columns, 
         loc='top')

说明

100 XP

请在 Shell 中查看 meat_mean —— 一个包含 meat 中所有时间序列均值的 DataFrame。

  • 将 meat_mean 的所有数值传给 cellText 参数。
  • 将 meat_mean 的索引传给 rowLabels 参数。
  • 将 meat_mean 的列名传给 colLabels 参数。