SQLAlchemy และ pandas สำหรับการแสดงผล

Python เบื้องต้นสำหรับฐานข้อมูล

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

SQLAlchemy และ pandas

  • DataFrame รับ ResultSet ของ SQLAlchemy ได้
  • ต้องกำหนดคอลัมน์ของ DataFrame ให้ตรงกับ keys ของ 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()

barplot.png

Python เบื้องต้นสำหรับฐานข้อมูล

มาฝึกกันเถอะ!

Python เบื้องต้นสำหรับฐานข้อมูล

Preparing Video For Download...