Trying to import this .csv into sqlite with python and getting an error:
import csv, sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("CREATE TABLE t (ID, LIMIT_BAL, SEX, EDUCATION, MARRIAGE, AGE, PAY_0, PAY_2, PAY_3, PAY_4, PAY_5, PAY_6, BILL_AMT1, BILL_AMT2, BILL_AMT3, BILL_AMT4, BILL_AMT5, BILL_AMT6, PAY_AMT1, PAY_AMT2, PAY_AMT3, PAY_AMT4, PAY_AMT5, PAY_AMT6, Default);")
with open('C:\\Users\\Joseph\\Desktop\\W7\\UCI_Credit_Card.csv','rb') as fin:
dr = csv.DictReader(fin)
to_db = [(i['col1'], i['col2']) for i in dr]
cur.executemany("INSERT INTO t (col1, col2) VALUES (?, ?);", to_db)
con.commit()
con.close()'''
Error: >>> ================ RESTART: C:/Users/Joseph/Desktop/W7/Wk7test.py ================ Traceback (most recent call last): File "C:/Users/Joseph/Desktop/W7/Wk7test.py", line 5, in cur.execute("CREATE TABLE t (ID, LIMIT_BAL, SEX, EDUCATION, MARRIAGE, AGE, PAY_0, PAY_2, PAY_3, PAY_4, PAY_5, PAY_6, BILL_AMT1, BILL_AMT2, BILL_AMT3, BILL_AMT4, BILL_AMT5, BILL_AMT6, PAY_AMT1, PAY_AMT2, PAY_AMT3, PAY_AMT4, PAY_AMT5, PAY_AMT6, Default);") sqlite3.OperationalError: near "Default": syntax error
defaultis a SQLite keyword: sqlite.org/lang_keywords.html You'll need to rename that column.