I have some problems with parsing huge csv file into mysql databse.
Csv file looks like this:
ref1 data1 data2 data3...
ref1 data4 data5 data6...
ref2 data1 data2 data3 data4 data5..
ref2 data12 data13 data14
ref2 data21 data22...
.
.
.
Csv file has about 1 milion lines or about 7MB in zip file or about 150MB unzip.
My job is to parse the data from csv into mysql, but only the data/lines when references matches. Another problem is, that from multiple lines in csv i must parse it in only one line in mysql for one reference.
I tryed to do this with csv.reader and for loops on each references, but is ultra slow.
with con:
cur.execute("SELECT ref FROM users")
user=cur.fetchall()
for i in range(len(user)):
with open('hugecsv.csv', mode='rb') as f:
reader = csv.reader(f, delimiter=';')
for row in reader:
if(str(user[i][0])==row[0]):
writer.writerow(row)
So i have all references which i would like to parse, in my list user. Which is the fastes way to parse?
Please help!