開始使用免費開始

從 SQLAlchemy 結果到圖表

我們也可以善用 pandasMatplotlib 來將資料繪製成圖。記住,資料視覺化對探索性資料分析與溝通你的資料都至關重要!

本練習屬於課程

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

編輯並執行程式碼