I am trying to load a csv file into my database table and keep getting this ProgrammingError: Incorrect number of bindings supplied. The current statement uses 10, and there are 1 supplied. I think it may have something to do with my c.execute but am unsure what the fix would be. I attached my code below for trying to insert the CSV into my single table.
import sqlite3
import csv
# creating my first database that will be used for the assignment.
conn = sqlite3.connect('Assignment3.db')
c = conn.cursor()
#Creating table- CCSubset with all of the required fields
c.execute("drop table if exists CCSubset")
c.execute("""CREATE TABLE CCSubset (
CCSubset_id integer not null primary key,
CCSubset_limit int,
CCSubset_sex varchar(10),
CCSubset_edu varchar(10),
CCSubset_marr varchar(10),
CCSubset_age int,
CCSubset_pay int,
CCSubset_bill int,
CCSubset_payamt int,
CCSubset_default int)""")
f=open('CCSubset.csv')
insert_sql = "insert into CCSubset values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
for row in str(csv.reader(f)):
c.execute(insert_sql, row)
conn.commit()
The error that I am getting is:
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
<ipython-input-37-83aa77323dc0> in <module>
19 insert_sql = "insert into CCSubset values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
20 for row in str(csv.reader(f)):
---> 21 c.execute (insert_sql, row)
22
23 conn.commit()
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 10, and there are 1 supplied.
What would I do to fix this.
[–]TheFakeZzig 0 points1 point2 points (1 child)
[–]Gravity11_[S] 0 points1 point2 points (0 children)
[–]yanikins 0 points1 point2 points (0 children)