On 10 April 2017 at 15:17, David Shi via Python-list
<python-list@python.org> wrote:
> In the data set, pound sign escape appears:
> u'price_currency': u'\xa3', u'price_formatted': u'\xa3525,000',
> When using table.to_csv after importing pandas as pd, an error message 
> persists as follows:
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 
> 0: ordinal not in range(128)
>

The error indicates clearly that you have a character which is not part
of the standard ASCII range, hence the message : "ordinal not in range(128)"
To understand it better, try to imagine characters as numbers and that basic
ASCII defines characters in this range.
see http://www.ascii-code.com/
So the pound character is out this range, its ordinal is being read by
your program as #a3 in hex (#163 in decimal). So *probably* your data
originally is in Latin-1 encoding,

First , you should find out where the data comes from:
is it text file, or some input, then in which application and
encoding was it created.

To get rid of errors, I'd say there are 2 common strategies:
ensure that all source data is saved in Unicode (save as UTF-8)
Or, replace the pound sign with something which is
representable in standard ASCII, e.g. replace the
pound sign with "GBP" in sources.

Otherwise, you must find out which encoding is
used in source data and apply re-encoding
accordingly to input-output format specification.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to