python - SQL multiple inserts inside for loop -


connection.execute("""create table if not exists bystate (         date text,         avetemp real,         avetempun real,         state varchar(20),         country varchar(20) )""") connection.commit() 

i have database table need insert thousands records (from excel document). i'm using xlrd read excel file. insert table using loop.

for in range(1,sheet.nrows):     data=sheet.row_values(i)     store=tempbycountry(date=data[0],averagetemp=data[1],tempuncert=data[2],country=data[3])     connection.execute("insert bycountry values (:date, :avetemp, :avetempun, :country)", {'date': data.date,'avetemp': data.averagetemp,'avetempun': data.tempuncert,'country': data.country})     connection.commit()  print("records stored bycountry") 

the problems:

  1. xlrd reads excel file (contains 500,000 rows).
  2. records added @ 10 20 inserts per second. it's impossible work this, took hours.

i'm using python3, sqlite3 , xlrd.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -