python - How can I improve my INSERT statement performance? -
How to insert a 256x64x250 value array in a MySQL database When I actually tried my INSERT statement on my data So it turned out very slow (in 6 minutes for a 16 minute file). Include "` data` (frame, sensor_ro, sensor_col, value) values (% s,% s,% s,% s) for frames in range (NA): For rows in category (NA): For the Colonel Range (NX): cursor. Execute (query, (frame, rows, columns, data [rows, columns, frames]))
I was reading, who said that This was not the right approach because it is very difficult to execute 4 million separate inserts.
Now my data There is a lot of void (actually more than 90%), so I threw into the IF statement. Only enter more than zero value and I have used executemany () instead: For rows in the category (NA) in the `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` `` For the rows in the range (nx) S,% s,% s,% s) "" "value = [] frame in range (nj): if data [rows, cols, frames] & gt; 0.0: value.append (frame, lines, columns, data [rows, columns, frames]) cur.executemany (query, value) This miraculously brought down my processing time About 20 seconds, out of which in 14 seconds the list of values (37k rows) and 4 seconds is actually spent on formatting the database. Now I am thinking, 'How can I move this process forward?' Because I think my loop is extremely inefficient and should be a better way. If I need to put 30 measurements for every dog, it can still take 10 minutes, which seems too long for the amount of this data. Here are two versions of my raw files: or I would love to try Loading data INFILE, but I can not understand how to parse the data correctly. If the data is a numpy array, you can try it: or
query = "" include `data` (frame, sensor_ro, sensor_col, value) in values (% s), rows, columns, rows, columns in frames, rows, columns, frames = numpy for frames. Nonzero (data) "" "" "" values = [] rows:. Frame, line, call, data [row, call, frame]) cur.executemany (query, value)
query = "" Enter the values in the data (frame, sensor_roo, sensor_col, value) (% s,% s,% s,% s) rows, cols, frame = numpy.nonzero (data) value = [(line, Columns, frames, data [rows, columns, frames])] for cur.executemany (query, value) call, call, frame, call for wallet, frame, p > Hope this helps
Comments
Post a Comment