pandas 提供的绑定数不正确,当前语句使用2,而提供了3

w46czmvw  于 2022-11-20  发布在  其他
关注(0)|答案(1)|浏览(175)

我正在尝试将数据从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.
knpiaxh1

knpiaxh11#

.pop()不是你想要的(它返回弹出的元素--第三列,然后Python试图迭代字符串中的字母)。你需要使用切片来代替。如果你想保留前两列,

row.split(',')[:2]

相关问题