使用 pandas 的精實資料導入
Amany Mahfouz
Instructor






sqlalchemy 的 create_engine() 會建立處理資料庫連線的引擎sqlite:///filename.dbpd.read_sql(query, engine) 從資料庫載入資料query:要執行的 SQL 查詢字串或要載入的資料表engine:連線/資料庫引擎物件SELECT [column_names] FROM [table_name];
SELECT * FROM [table_name];
# 載入 pandas 與 sqlalchemy 的 create_engine import pandas as pd from sqlalchemy import create_engine# 建立資料庫引擎以管理連線 engine = create_engine("sqlite:///data.db")# 以表名載入整個 weather 資料表 weather = pd.read_sql("weather", engine)
# 建立資料庫引擎以管理連線 engine = create_engine("sqlite:///data.db")# 以 SQL 載入整個 weather 資料表 weather = pd.read_sql("SELECT * FROM weather", engine)print(weather.head())
station name latitude ... prcp snow tavg tmax tmin
0 USW00094728 NY CITY CENTRAL PARK, NY US 40.77898 ... 0.00 0.0 52 42
1 USW00094728 NY CITY CENTRAL PARK, NY US 40.77898 ... 0.00 0.0 48 39
2 USW00094728 NY CITY CENTRAL PARK, NY US 40.77898 ... 0.00 0.0 48 42
3 USW00094728 NY CITY CENTRAL PARK, NY US 40.77898 ... 0.00 0.0 51 40
4 USW00094728 NY CITY CENTRAL PARK, NY US 40.77898 ... 0.75 0.0 61 50
[5 rows x 13 columns]
使用 pandas 的精實資料導入