Blue Moon
Blue Moon

Reputation: 4651

UnicodeEncodeError: 'ascii' codec can't encode character

I'am trying to export as csv a pandas dataframe with the function:

outcome.to_csv("/Users/john/out_1.csv")

I get the following error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 191: ordinal not in range(128)

how do I go to position 191 to check what's wrong?

Many thanks

Upvotes: 1

Views: 2148

Answers (1)

Anant Gupta
Anant Gupta

Reputation: 1149

    outcome.to_csv("/Users/john/out_1.csv",encoding="utf-8")

On referring to the documentation of pandas.to_csv, we have the following details. It seems that for Python 2.7 the default is "ascii" which needs to be overridden to "utf-8"

encoding : string, optional

A string representing the encoding to use in the output file, defaults to ‘ascii’ on Python 2 and ‘utf-8’ on Python 3.

Upvotes: 1

Related Questions