Reputation: 4651
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
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