Pandas to_sql fails on duplicate primary key

后端 未结 6 1167
执笔经年
执笔经年 2020-12-28 18:13

I\'d like to append to an existing table, using pandas df.to_sql() function.

I set if_exists=\'append\', but my table has primary keys.

6条回答
  •  自闭症患者
    2020-12-28 18:25

    Pandas doesn't support editing the actual SQL syntax of the .to_sql method, so you might be out of luck. There's some experimental programmatic workarounds (say, read the Dataframe to a SQLAlchemy object with CALCHIPAN and use SQLAlchemy for the transaction), but you may be better served by writing your DataFrame to a CSV and loading it with an explicit MySQL function.

    CALCHIPAN repo: https://bitbucket.org/zzzeek/calchipan/

提交回复
热议问题