To explore quickly with Pandas your database, you can use this code:
tables = pd.read_sql_query("SELECT * FROM sqlite_schema WHERE type='table'", cnx)
for tbl in tables['name']:
print(f"{'*'*10} {tbl} {'*'*10}")
columns = pd.read_sql_query(f"PRAGMA table_info({tbl})", cnx)
print(columns, end='\n\n')
data = pd.read_sql_query(f"SELECT * FROM {tbl} LIMIT 5", cnx)
print(data, end='\n\n')
Sample output:
********** UserConstraint **********
cid name type notnull dflt_value pk
0 0 ID INTEGER 1 None 1
1 1 Name VARCHAR(255) 0 None 0
ID Name
0 0 <NA>
1 1 INSTCAP
2 2 LUMPINV
3 3 INV
4 4 COST
********** Cap_New **********
cid name type notnull dflt_value pk
0 0 ID INTEGER 1 None 1
1 1 Scenario SMALLINT 0 None 0
2 2 Process SMALLINT 0 None 0
3 3 Period SMALLINT 0 None 0
4 4 Region SMALLINT 0 None 0
5 5 Vintage SMALLINT 0 None 0
6 6 UserConstraint SMALLINT 0 None 0
7 7 PV FLOAT 0 None 0
ID Scenario Process Period Region Vintage UserConstraint PV
0 1 1 211 1 1 1 1 296.071141
1 2 1 212 1 1 1 1 11.770909
2 3 1 343 1 1 1 1 11851.674497
3 4 1 949 2 1 2 1 43.000000
4 5 1 691 2 1 2 1 5.488316
Note: don't forget to print tables
.