英文:
str not tuple error when running pandas code
问题
我正在创建一个记忆问答游戏,其中使用Python向用户询问他们的一天。
我试图使用matplotlib和pandas创建一个进度图,但是当我运行代码时,我遇到以下错误:
pandas.errors.DatabaseError: 在SQL查询上执行失败:('SELECT Date, Score FROM scoring WHERE UserID =?', ('Kgarda43',)):execute()的第1个参数必须是字符串,而不是元组
这是我遇到错误的代码部分:
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) # 收集数据
任何帮助都将非常感谢。谢谢!
英文:
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!
答案1
得分: 1
我怀疑你数据库中的UserID字段应该是一个字符串,因此在发现这个错误后:
execute() argument 1 must be str, not tuple
你可以通过正确使用逗号来修复它,将其放入你的查询中:
sql = '''
SELECT Date, Score
FROM scoring
WHERE UserID = ?
'''
英文:
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 ='?'
'''
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论