Я испытываю низкую производительность при использовании Pandas для загрузки данных из файла Excel в существующую таблицу Redshift. Файл Excel содержит более 10 столбцов и более 20 000 строк, а выполнение операции занимает более 7 часов. Есть ли способ оптимизировать код и повысить производительность? Обратите внимание, что у меня нет доступа к S3 и я не могу использовать его как опцию.
# Establish a connection to Redshift
conn = psycopg2.connect(
host='your-redshift-host',
port='your-redshift-port',
user='your-username',
password='your-password',
dbname='your-database'
)
# Copy the contents of excel_file to a dataframe
df = pd.read_excel(excel_file)
# Insert dataframe records into the table
cur = conn.cursor()
cur.execute('TRUNCATE TABLE table_name')
insert_query = "INSERT INTO table_name (tablecolumn1, tablecolumn2, tablecolumn3) VALUES (%s, %s, %s)"
for index, row in df.iterrows():
cur.execute(insert_query, (row['dfcolumn1'], row['dfcolumn2'], row['dfcolumn3']))
conn.commit()
cur.close()