0

I have exported several tables from SQLite into a dictionary. Is there a way to extract all of the dataframes that are now in the dictionary and create one dataframe for each ? (ex. df1, df2, df3, etc...)

conn = sq3.connect('C:/Users/database.db')
cur = conn.cursor()

cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
tablenames = cur.fetchall()

df_dict = {}
for tablename in tablenames:
    tablename = tablename[0]
    df_dict[tablename] = pd.read_sql_query('SELECT * FROM %s' % tablename, conn).set_index('date')
pma
  • 1
  • 1
  • [This](https://stackoverflow.com/questions/42466639/how-can-i-convert-a-dictionary-to-a-pandas-dataframe) can be helpful – Alperen Sep 20 '17 at 08:37
  • Are you asking to dynamically create variables within your for-loop? – Brad Solomon Sep 20 '17 at 11:41
  • If a for-loop is the only way, then yes the variable names for each dataframe will probably need to be created dynamically (if that is possible, not sure...) I was thinking however more along the lines of accessing the dataframes directly in the dictionary and simply using the already defined keys as dataframe variable name. – pma Sep 20 '17 at 11:57

0 Answers0