Ingestie eficientă a datelor cu pandas
Amany Mahfouz
Instructor






create_engine() din sqlalchemy creează un motor pentru gestionarea conexiunilor la baze de datesqlite:///filename.dbpd.read_sql(query, engine) pentru a încărca date dintr-o bază de datequery: Șir de caractere cu interogarea SQL sau numele tabeluluiengine: Obiect de tip conexiune/motor de baze de dateSELECT [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]
Ingestie eficientă a datelor cu pandas