python - Encoding error in Pandas DataFrame -


in pandas dataframe, when writing csv can encode file adding argument encoding='utf-8'

however there issue this. if getting data directly database , placing directly dataframe, when writing csv, encoding error:

unicodeencodeerror: 'ascii' codec can't encode characters in position 24-25: ordinal not in range(128) 

so decoding/encoding needs happen prior placing data datframe.

does have simple solution this?

if creating dataframe database, can use read_sql:

df = pd.read_sql('select * foo', con) 

here con connection object, e.g. created using sqlite3 or mysqldb.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -