-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverify_db.py
More file actions
26 lines (22 loc) · 792 Bytes
/
Copy pathverify_db.py
File metadata and controls
26 lines (22 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Quick verification of the SQLite database after ETL."""
import sqlite3
import pandas as pd
conn = sqlite3.connect("db/pfa.db")
cur = conn.cursor()
# List all tables
cur.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name")
tables = cur.fetchall()
print("Tables in pfa.db:")
print("-" * 60)
for (t,) in tables:
cur.execute(f"SELECT COUNT(*) FROM [{t}]")
count = cur.fetchone()[0]
cur.execute(f"PRAGMA table_info([{t}])")
cols = [row[1] for row in cur.fetchall()]
print(f" {t:30s} {count:>6} rows cols: {cols}")
# Samples
for table in ["data_reel", "mapping", "clients", "data_budget_topline"]:
print(f"\n--- {table} (first 5 rows) ---")
df = pd.read_sql(f"SELECT * FROM [{table}] LIMIT 5", conn)
print(df.to_string())
conn.close()