Python中sqlite3错误提示:
代码如下:
df = pandas.DataFrame(newsdetail)
df.to_excel('news1.xls')
import sqlite3
with sqlite3.connect('news.sqlite') as db:
df.to_sql('news',con = db)
df2 = pandas.read_sql_query('SELECT * FROM news',con = db)
print(df2)
请问问题出在哪里?刚接触Python,看着教程原封不动翘出来的代码。
根据 @剑心无痕 的答案提示,终于找到出现这种错误的原因。
sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.
出现这个错误是应为
newsdetail(一个字典列表)其中一个字典的值是列表,所以会提示出错。如果把列表换成字符串就会正常。