samedi 24 janvier 2015

Bulk import/load csv to sqlite using Python

i have searched for a method to do a bulk import of a csv to sqlite using python script.


Currently i am using an insert which runs for every row of the csv:



with open('file_name.csv','rb') as fin:
Read_csv = csv.DictReader(fin) # comma is default delimiter
to_db = [(i['col1'],i['col2'],i['col3']) for i in Read_csv]
DbCur.executemany("INSERT INTO table (col1,col2,col3) values (?,?,?);",to_db)


I need a method to bulk insert the entire data instead of inserting row by row which i think is not very optimized coding. Any help is appreciated.


Aucun commentaire:

Enregistrer un commentaire