การนำเข้าข้อมูลด้วย pandas อย่างมีประสิทธิภาพ
Amany Mahfouz
Instructor






create_engine() ของ sqlalchemy สร้าง engine สำหรับจัดการการเชื่อมต่อฐานข้อมูลsqlite:///filename.dbpd.read_sql(query, engine) เพื่อโหลดข้อมูลจากฐานข้อมูลquery: string ที่ระบุ SQL query หรือชื่อตารางที่ต้องการโหลดengine: อ็อบเจกต์ connection/database engineSELECT [column_names] FROM [table_name];
SELECT * FROM [table_name];
# Load pandas and sqlalchemy's create_engine import pandas as pd from sqlalchemy import create_engine# Create database engine to manage connections engine = create_engine("sqlite:///data.db")# Load entire weather table by table name weather = pd.read_sql("weather", engine)
# Create database engine to manage connections engine = create_engine("sqlite:///data.db")# Load entire weather table with SQL 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 อย่างมีประสิทธิภาพ