【发布时间】:2015-03-09 18:39:31
【问题描述】:
我有问题。大约有数百个 CSV 文件。每一行有 1,000,000 行。 我需要以特定方式移动该数据,但脚本运行速度非常慢(每小时通过几十万)。
我的代码:
import sqlite3 as lite
import csv
import os
my_file = open('file.csv', 'r')
reader = csv.reader(my_file, delimiter=',')
date = '2014-09-29'
con = lite.connect('test.db', isolation_level = 'exclusive')
for row in reader:
position = row[0]
item_name = row[1]
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS [%s] (Date TEXT, Position INT)" % item_name)
cur.execute("INSERT INTO [%s] VALUES(?, ?)" % item_name, (date, position))
con.commit()
我找到了一个关于isolation_level和single access to database的信息,但是效果不好。
行 CSV 文件具有以下结构:1,item1 | 2、项目2
有人可以帮助我吗?谢谢!
【问题讨论】: