Streamlined Data Ingestion with pandas
Amany Mahfouz
Instructor






create_engine() z sqlalchemy vytváří engine pro správu připojení k databázisqlite:///filename.dbpd.read_sql(query, engine) pro načtení dat z databázequery: řetězec s SQL dotazem nebo názvem tabulkyengine: objekt připojení k databáziSELECT [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]
Streamlined Data Ingestion with pandas