pythonbeginner

SQLite + Pandas Local Data Pipeline

Run a lightweight local ETL with SQLite and pandas: load CSV, transform, persist to SQLite.

python
import sqlite3
import pandas as pd

df = pd.read_csv('sales.csv', parse_dates=['date'])
df['month']   = df['date'].dt.to_period('M')
df['revenue'] = df['price'] * df['qty']

monthly = df.groupby('month')['revenue'].sum().reset_index()
monthly['month'] = monthly['month'].astype(str)

con = sqlite3.connect('analytics.db')
monthly.to_sql('monthly_revenue', con, if_exists='replace', index=False)
print(pd.read_sql('SELECT * FROM monthly_revenue LIMIT 5', con))
con.close()

Use Cases

  • local analytics
  • prototyping
  • lightweight data pipelines

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.