I have been stuck for a while with a UnicodeEncodeError
in Python.
Here is what I am doing:
- I create a Dataframe as a result of a various analysis. In total, the dataframe has 30 columns with multiple types of values (
int
,string
,datetime
,etc). - I create an SSH connection to a remote instance in Azure where I have installed MySQL. I create the connection using
SQLAlchemy
. - I run the
df.to_sql
command and get the following error
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2013' in position 8: ordinal not in range(256)
I tried doing this but it didn't seem to work.
engine = create_engine('mysql+pymysql://user:pwd@host:%s/db?charset=utf8' % server.local_bind_port)
I have read here that I can use u.encode('latin-1', 'replace')
. But would I need to perform that and go through every String
column and encode it? Or is there something else that I can do?