Loading Data from SQL to Python
It's **Day 104**, and we're connecting the dots.
The Old Way (Slow)
1. Run SQL in a tool like DBeaver.
2. Export as CSV.
3. Load CSV into Python.
The Professional Way (Automated)
We use a library like `sqlalchemy` or `psycopg2` to let Python talk to the database directly.
import pandas as pd
from sqlalchemy import create_engine
# 1. Connect to the DB
engine = create_engine('postgresql://user:pass@localhost:5432/mydb')
# 2. Run your SQL directly into a DataFrame!
query = "SELECT * FROM sales WHERE amount > 1000"
df = pd.read_sql(query, engine)
print(df.head())
Why this is a game changer
You can now automate your reports. Imagine a script that runs every Monday morning, pulls the latest sales, builds a chart, and emails it to your boss. This is the foundation of **Data Engineering**.
Your Task for Today
Research "SQLAlchemy connection strings" for the specific database you use (Postgres, MySQL, SQLite, etc).
*Day 105: Filtering Data with Boolean Indexing.*