I am struggling to understand why this returns a list containing a DataFrame rather than only the DataFrame. Is there something wrong with the code or a way to return only the DataFrame? It works as expected if not placed within a function.
import sqlite3
import pandas as pd
def get_tbl_info(db ='MyDatabase', table ='Measurements'):
database = "/Users/Mary/Documents/Database/{DB}.db"..format(DB=db)
conn = sqlite3.connect(database)
tbl_info_command = "PRAGMA TABLE_INFO({table});".format(table=table)
result_all = pd.read_sql_query(tbl_info_command,conn)
print(type(result_all))
return [result_all]
out = get_tbl_info()
print(type(out))
gives:
<class 'pandas.core.frame.DataFrame'>
<class 'list'>
return [result_all]. Try justreturn result_all.