开始使用免费开始使用

从 SQLAlchemy 结果到图表

我们还可以借助 pandas 和 Matplotlib 将数据可视化成图形。请记住,数据可视化对于探索性数据分析和传达您的数据都至关重要!

本练习是课程的一部分

Python 中的数据库入门

查看课程

练习说明

  • matplotlib.pyplot 以别名 plt 导入。
  • 使用提供的 results 调用 pd.DataFrame() 创建 DataFrame df
  • 将 DataFrame 的列 df.columns 设置为首个结果对象的列名 results[0].keys()
  • 打印 DataFrame df
  • df 上使用 plot.bar() 方法创建结果的柱状图。
  • 使用 plt.show() 显示图表。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import pyplot as plt from matplotlib


# Create a DataFrame from the results: df
df = ____

# Set Column names
df.columns = ____

# Print the DataFrame


# Plot the DataFrame

编辑并运行代码