SQLAlchemy và pandas để trực quan hóa

Nhập môn Cơ sở dữ liệu với Python

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

SQLAlchemy và pandas

  • DataFrame có thể nhận ResultSet của SQLAlchemy
  • Đặt tên cột DataFrame theo các khóa của ResultSet
Nhập môn Cơ sở dữ liệu với Python

Ví dụ 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
Nhập môn Cơ sở dữ liệu với Python

Vẽ biểu đồ

  • Vẽ biểu đồ như thông thường
Nhập môn Cơ sở dữ liệu với Python

Ví dụ vẽ biểu đồ

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

Biểu đồ cột ngang

Nhập môn Cơ sở dữ liệu với Python

Hãy luyện tập!

Nhập môn Cơ sở dữ liệu với Python

Preparing Video For Download...