Sprawne importowanie danych z pandas
Amany Mahfouz
Instructor






create_engine() z sqlalchemy tworzy silnik do obsługi połączeń z baząsqlite:///filename.dbpd.read_sql(query, engine) – wczytuje dane z bazy danychquery: ciąg znaków z zapytaniem SQL lub nazwą tabeliengine: obiekt połączenia/silnika bazy danychSELECT [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]
Sprawne importowanie danych z pandas