Spaces:
Sleeping
Sleeping
File size: 489 Bytes
af733da 61e83c9 af733da |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import sqlite3
import pandas as pd
def execute_query_and_return_df(query):
"""
Executes a SQL query and returns the results as a Pandas DataFrame.
Args:
query: The SQL query to execute.
Returns:
A Pandas DataFrame containing the query results.
"""
conn = sqlite3.connect("Chinook_Sqlite.sqlite")
try:
df = pd.read_sql_query(query, conn)
return df
except Exception as e:
print(f"Error executing query: {e}")
return None
finally:
conn.close() |