我正在尝试使用SQLAlchemy将pandas数据帧中的数据附加到sqlserver中的现有表中,但由于SQL的速度非常慢,所以我正在寻找一种高效的、可扩展的解决方案来加快这一速度。我已经看到了许多建议的解决方案,尽管其中许多建议使用批量插入,这可能是错误的,但是数据帧不能存储在本地。我尝试过其他的解决方案,比如快速执行,但都没有用。感谢您的帮助。你知道吗
def uploadToSQL(df, tablename, user, if_exists_behavior = 'append'):
try:
## Create connection to SQL
engine = sqla.create_engine(user)
print("establishing connection")
conn = engine.connect()
print("connection established")
df.to_sql(tablename, engine, if_exists=if_exists_behavior,
index=False, chunksize = 49)
print("table uploaded")
## close SQL connection
conn.close()
print("connection closed")
## since no failure return nothing
return None
此函数完成此任务,但对于16000 x 6数据帧需要很长时间。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐