載入整張資料表
在上一個練習中,你看到 data.db 中有兩張資料表。weather 存有紐約市的歷史天氣資料。hpd311calls 則是市府 311 求助專線中,與住房問題相關通話紀錄的子集。
在這個練習中,你會使用 pandas 的 read_sql() 來載入這兩張表。read_sql() 接受一個字串,內容可以是要執行的 SQL 查詢,或是要載入的資料表名稱。它也需要一個連線到資料庫的方式,例如提供程式碼中的 engine。
本練習屬於課程
使用 pandas 的精實資料導入
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load libraries
import pandas as pd
from sqlalchemy import create_engine
# Create the database engine
engine = create_engine('sqlite:///data.db')
# Load hpd311calls without any SQL
hpd_calls = ____(____, ____)
# View the first few rows of data
print(hpd_calls.head())