【问题标题】:pandas: "Lost connection to MySQL server" "system error: 32 Broken pipe"熊猫:“丢失与 MySQL 服务器的连接”“系统错误:32 断管”
【发布时间】:2019-02-19 19:24:23
【问题描述】:

尝试导入 pandas 数据框时出现上述错误:

import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mysql://username:password@localhost/dbname')
c = getsomedata()
fields = ['user_id', 'timestamp', 'text']
c1 = c[fields].reset_index()
c1.to_sql(name='comments', con=engine, if_exists='replace', index=False)

这个 MySql 问题有很多问题 - 但是如何通过 pandas 导入来解决?

【问题讨论】:

    标签: python mysql pandas sqlalchemy


    【解决方案1】:

    对我来说解决方案非常简单:使用chunksize 选项:

    c1.to_sql(name='comments', con=engine, chunksize=1000, if_exists='replace', index=False)
                                           ^^^^^^^^^^^^^^^
    

    可能与带有过大数据包的this issue 有关。

    【讨论】:

    • 这拯救了我的一天。谢谢@ErichBSchulz
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 2021-05-07
    相关资源
    最近更新 更多