Pandas Write table to MySQL: “unable to rollback”

前端 未结 4 1283
遥遥无期
遥遥无期 2021-01-12 13:53

I need help to get this working. I have a pd.DataFrame (df), which I need to load to a MySQL database. I don\'t understand what the error message means and how

4条回答
  •  Happy的楠姐
    2021-01-12 14:33

    When using sqlalchemy, you should pass the engine and not the raw connection:

    engine = create_engine("mysql+mysqldb://...")
    df.to_sql('demand_forecast_t', engine, if_exists='replace', index=False)
    

    Writing to MySQL without sqlalchemy (so with specifying flavor='mysql') is deprecated.

    When the problem is that you have a too large frame to write at once, you can use the chunksize keyword (see the docstring). Eg:

    df.to_sql('demand_forecast_t', engine, if_exists='replace', chunksize=10000)
    

提交回复
热议问题