用于可视化的 SQLAlchemy 与 pandas

Python 中的数据库入门

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

SQLAlchemy 与 pandas

  • DataFrame 可接收 SQLAlchemy 的 ResultSet
  • 将 DataFrame 的列设置为 ResultSet 的键
Python 中的数据库入门

DataFrame 示例

import pandas as pd

df = pd.DataFrame(results)
df.columns = results[0].keys()
print(df)
    sex  pop2008_sum
0     F      2105442
1     F      2087705
2     F      2037280
3     F      2012742
4     F      2014825
5     F      1991082
Python 中的数据库入门

绘图

  • 可以像平常一样绘图
Python 中的数据库入门

绘图示例

import matplotlib.pyplot as plt
df[10:20].plot.barh()
plt.show()

条形图

Python 中的数据库入门

让我们练习!

Python 中的数据库入门

Preparing Video For Download...