我有一个 1,000,000
x 50
的Pandas DataFrame
,目前正在使用以下代码将其写入SQL表中:
df.to_sql('my_table', con, index=False)
这需要很长时间。我在网上看到了各种加速此过程的方法,但似乎没有一种适用于MSSQL的。
如果我尝试以下方法:
Bulk Insert A Pandas DataFrame Using SQLAlchemy
那么我会得到一个
no attribute copy_from
错误。如果我尝试以下方法中的多线程方法:
http://techyoubaji.blogspot.com/2015/10/speed-up-pandas-tosql-with.html
那么我会得到一个
QueuePool limit of size 5 overflow 10 reach, connection timed out
错误。
是否有任何简单的方法可以加速将数据写入MSSQL表格?无论是通过BULK COPY还是其他方法,但完全在Python代码内部实现?