用 SQLAlchemy 與 pandas 做視覺化

Python 資料庫入門

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

SQLAlchemy 與 pandas

  • DataFrame 可接收 SQLAlchemy 的 ResultSet
  • 記得把 DataFrame 欄位設為 ResultSet 的 keys
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...