I have a dataframe with 4 million rows, I use to_sql to insert it into an exist table, but it takes almost 2 hours to finish the insert, is there a way to speed up?
I use this method:
import pandas as pd
from sqlalchemy import create_engine, types
def _execute_insert(self, conn, keys, data_iter):
data = [dict((k,v) for k, v in zip(keys, row)) for row in data_iter]
conn.execute(self.insert_statement().values(data))
df.to_sql(raw_table_name[i], con=db, index=False, if_exists='append',chunksize=50000)
is there a way to speed up?