'latin-1' codec can't encode character u'\u2014' in position 23: ordinal not in range(256)

这一生的挚爱 提交于 2019-12-13 14:20:44

问题


I am loading data into a pandas dataframe from an excel workbook and am attempting to push it to a database when I get the above error.

I thought at first the collation of the database was at issue which I changed to utf8_bin

Next I checked the database engine create statement on my end which I added a parameter for the encoding too.

engine = create_engine('mysql+pymysql://root@localhost/test', encoding="utf-8")

But neither of these things work I am still getting the error from the line:

df.to_sql("strand", engine, if_exists="append", index=False)

I checked if there was an encoding parameter for the to_sql method but this does not seem to be the case.


回答1:


Apparently I needed to add ?charset-utf8 to the query string as well as the encoding variable which resulted in me ending up wht the engine create statement

engine = create_engine('mysql+pymysql://root@localhost/test?charset=utf8', encoding="utf-8")


来源:https://stackoverflow.com/questions/27488032/latin-1-codec-cant-encode-character-u-u2014-in-position-23-ordinal-not-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!