With sqlite3 in Python if I want to make a db query using a variable instead of a fixed command I can do something like this :
name = 'MSFT'
c.execute('INSERT INTO Symbol VALUES (?) ', (name,))
And when I try to access the SQL db using pandas data frame I can do this:
df = pd.read_sql_query('SELECT open FROM NYSEXOM', conn)
However I am unsure how to load data from SQL to a pandas data frame while referencing a variable. I have tried the following:
conn = sqlite3.connect('stocks.db')
dates= [20100102,20100103,20100104]
for date in dates:
f = pd.read_sql_query('SELECT open FROM NYSEMSFT WHERE date = (?)', conn, (date,))
When I run this I get an error saying "Incorrect number of bindings supplied, The current statement uses 1, and there are 0 supplied"
How can I properly format a command to load SQL data into a pandas data frame using a variable reference?