我正在尝试将数据从CSV迁移到SQLite数据库。CSV有3列,而表只有2列。我尝试弹出()由row.split(',')返回的列表中的最后一个元素,但它给出了不同的错误
Github link to csv
密码:
seen = set();
with open("E:/Forage/Walmart/task4/shipping_data_1.csv",'r') as file:
for row in file:
if row in seen: continue
seen.add(row)
cur.execute("INSERT INTO product values(?,?)",row.split(',').pop())
con.commit();
con.close()
错误:何时
cur.execute("INSERT INTO product values(?,?)",row.split(',')); is used
-->Incorrect number of bindings supplied. The current statement uses 2, and there are 3 supplied.
和
cur.execute("INSERT INTO product values(?,?)",row.split(',').pop()); is used
-->Incorrect number of bindings supplied. The current statement uses 2, and there are 8
supplied.
1条答案
按热度按时间knpiaxh11#
.pop()不是你想要的(它返回弹出的元素--第三列,然后Python试图迭代字符串中的字母)。你需要使用切片来代替。如果你想保留前两列,