3

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.

lathomas64
  • 1,612
  • 5
  • 21
  • 47

1 Answers1

9

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")
lathomas64
  • 1,612
  • 5
  • 21
  • 47
  • 1
    Thank you so very much for posting your own answer. I have spent alot of time finding out exactly that. Now it works! – Nemis May 27 '15 at 09:16