I have a list of tables in a column of a csv that I have read in as a dataframe into pandas like so:
df = pd.read_csv('~/tablenames')
tablenames csv looks like this:
tablenames table1 table2
The connection to the db and iterating through the dataframe is created like so:
import pandas as pd from sqlalchemy import create_engine df = pd.read_csv('~/tablenames') engine = create_engine('connection_string') for index,row in df.iterrows(): df['column_count'] = pd.read_sql_query("select count(column_name) from information_schema.columns where table_name = '%s'"%row['table_name'],con=engine) df['row_count'] = pd.read_sql_query("select count(*) from %s"%row['table_name'],con=engine)
The above loop is only getting the first tables data and is only executing the query for that first table in the dataframe. What am I doing wrong where the query is not executing for the rest of the table names in the dataframe?
I am not getting any error messages. If it helps I am connecting to a postgres db.
count 0 45 count 0 89 count 0 36 count 0 17 count 0 12