Complete the code to read a SQL table into a pandas DataFrame.
import pandas as pd import sqlite3 conn = sqlite3.connect('example.db') df = pd.read_sql_table([1], conn)
The read_sql_table function requires the table name as a string.
Complete the code to execute a SQL query and load the result into a DataFrame.
query = 'SELECT * FROM sales WHERE amount > 100' df = pd.read_sql_query([1], conn)
The read_sql_query function expects the SQL query string as the first argument.
Fix the error in the code to write a DataFrame to a SQL table.
df.to_sql([1], conn, if_exists='replace', index=False)
The first argument to to_sql must be the table name as a string.
Fill both blanks to create a DataFrame from a SQL query and set the index column.
df = pd.read_sql_query([1], conn, [2]='id')
The first argument is the SQL query string, and index_col sets the DataFrame index column.
Fill all three blanks to write a DataFrame to a SQL table with append mode and without the index.
df.to_sql([1], conn, if_exists=[2], index=[3])
if_exists='replace' which deletes existing data.index=True which writes the index as a column.Use the table name as a string, if_exists='append' to add data, and index=False to exclude the index.