Aaisha Garda
Aaisha Garda

Reputation: 21

str not tuple error when running pandas code

I'm creating a memory quiz game where it asks the user about their day (using python).

I'm trying to create a progress graph using matplotlib and pandas, however, when I run the code, I get the following error:

pandas.errors.DatabaseError: Execution failed on sql '('SELECT Date, Score FROM scoring WHERE UserID =?', ('Kgarda43',))': execute() argument 1 must be str, not tuple

This is my code for the area I am getting an error:

connection=sqlite3.connect('Memory.db')
cursor=connection.cursor()
sql=("SELECT Date, Score FROM scoring WHERE UserID =?", (Username_Login.value,))
data= pandas.read_sql(sql,connection)#collecting the data

Any help would be great. Thanks!

Upvotes: 0

Views: 84

Answers (1)

batu53
batu53

Reputation: 21

I suspect the UserID field in your database is supposed to be a string, therefore upon finding this error:

execute() argument 1 must be str, not tuple

You can fix it by correctly using your commas inside your query:

sql= '''
SELECT Date, Score 
FROM scoring 
WHERE UserID ='?'
     '''

Upvotes: 1

Related Questions