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:
- xlrd reads excel file (contains 500,000 rows).
- records added @ 10 20 inserts per second. it's impossible work this, took hours.
i'm using python3, sqlite3 , xlrd.
Comments
Post a Comment