Pound sign problem

Ben Finney ben+python at benfinney.id.au
Mon Apr 10 09:43:05 EDT 2017

David Shi via Python-list <python-list at python.org> writes:

> When using table.to_csv after importing pandas as pd

I don't know much about that library. What does its documentation say
for the ‘table.to_csv’ function?

Can you write a *very short* complete example, that we can run to
demonstrate the same behaviour you are seeing?

> an error message persists as follows:
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 0: ordinal not in range(128)

This means the function has been told (or is assuming, in the absence of
better information) that the input data is in the ‘ascii’ text encoding.

That assumption turns out to be incorrect, for the actual data you have.
So that error occurs.

You will need to:

* Find out exactly what text encoding was used to write the file. Don't
  guess, because there are many ways to be wrong.

* Specify that encoding to the ‘table.to_csv’ function, or to whatever
  function opens the file. (This might be the Python built-in ‘open’
  function, but we'd need to see your short example to know.)

 \        “Most people, I think, don't even know what a rootkit is, so |
  `\     why should they care about it?” —Thomas Hesse, Sony BMG, 2006 |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list