it's my first time working with sqlite3 and python together so I apologize for my noobness.
I'm a bit confused with how to write python code to correctly load certain columns from a csv file into SQLite3 database. There's a lot of columns in my file.
This is my code:
import sqlite3
import csv
connection = sqlite3.connect('revenue.db')
cursor = connection.cursor()
cursor.execute('DROP TABLE IF EXISTS TeamGameLogAllRegularSeason')
cursor.execute('CREATE TABLE TeamGameLogAllRegularSeason (Team_ID text, Game_ID text, GAME_DATE date, YEAR date, MATCHUP text, WL text, MIN integer, FGM integer, FGA integer, FG_PCT integer, FG3M integer, FG3A integer, FG3_PCT integer, FTM integer, FTA integer, FT_PCT integer, OREB integer, DREB integer, REB integer, AST integer, STL integer, BLK integer, TOV integer, PF integer, PTS integer, VIDEO_AVAILABLE integer)')
connection.commit()
csvfile = open('C:\\Python27\\nbadata_script\\1_TeamGameLogAllRegularSeason.csv','rb')
creader = csv.reader(csvfile, delimiter=',',quotechar='"')
for t in creader:
cursor.execute('INSERT INTO TeamGameLogAllRegularSeason VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',t)
csvfile.close()
connection.commit()
connection.close()
It works,table gets created but the error msg:
Traceback (most recent call last):
File "C:\Python27\nbadata_script\csvsqlite_exe.py", line 16, in <module>
cursor.execute('INSERT INTO TeamGameLogAllRegularSeason VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',t)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 26, and there are 0 supplied.
If anyone could help me, I would really appreciate it.