CSV to SQLite

import sqlite3 import csv conn = sqlite3.connect('lookup.sqlite') cur = conn.cursor() cur.execute("CREATE TABLE lookup(location TEXT, locality TEXT, eastings NUMERIC, northings NUMERIC)") reader = csv.reader(open('lookup.csv', "rb")) for row in reader: to_db = [unicode(row[0], "utf8"), unicode(row[1], "utf8"), row[2], row[3]] cur.execute("INSERT INTO lookup (location, locality, eastings, northings) VALUES (?, ?, ?, ?);", to_db) #cur.execute("CREATE INDEX location_idx ON lookup(location)" ) conn.commit()

Did this page help you?