Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:46:39+00:00 2026-05-16T11:46:39+00:00

I have an Excel spreadsheet that I’m reading in that contains some £ signs.

  • 0

I have an Excel spreadsheet that I’m reading in that contains some £ signs.

When I try to read it in using the xlrd module, I get the following error:

x = table.cell_value(row, col)
x = x.decode("ISO-8859-1")
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 0: ordinal not in range(128)

If I rewrite this to x.encode(‘utf-8’) it stops throwing an error, but unfortunately when I then write the data out somewhere else (as latin-1), the £ signs have all become garbled.

How can I fix this, and read the £ signs in correctly?

— UPDATE —

Some kind readers have suggested that I don’t need to decode it at all, or that I can just encode it to Latin-1 when I need to. The problem with this is that I need to write the data to a CSV file eventually, and it seems to object to the raw strings.

If I don’t encode or decode the data at all, then this happens (after I’ve added the string to an array called items):

for item in items:
    #item = [x.encode('latin-1') for x in item]
    cleancsv.writerow(item)
File "clean_up_barnet.py", line 104, in <module>
 cleancsv.writerow(item)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in position 43: ordinal not in range(128)

I get the same error even if I uncomment the Latin-1 line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:46:40+00:00Added an answer on May 16, 2026 at 11:46 am

    Your code snippet says x.decode, but you’re getting an encode error — meaning x is Unicode already, so, to “decode” it, it must be first turned into a string of bytes (and that’s where the default codec ansi comes up and fails). In your text then you say “if I rewrite ot to x.encode“… which seems to imply that you do know x is Unicode.

    So what it IS you’re doing — and what it is you mean to be doing — encoding a unicode x to get a coded string of bytes, or decoding a string of bytes into a unicode object?

    I find it unfortunate that you can call encode on a byte string, and decode on a unicode object, because I find it seems to lead users to nothing but confusion… but at least in this case you seem to manage to propagate the confusion (at least to me;-).

    If, as it seems, x is unicode, then you never want to “decode” it — you may want to encode it to get a byte string with a certain codec, e.g. latin-1, if that’s what you need for some kind of I/O purposes (for your own internal program use I recommend sticking with unicode all the time — only encode/decode if and when you absolutely need, or receive, coded byte strings for input / output purposes).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an excel spreadsheet that contains some formulas to calculate ROI for an
I have an Excel spreadsheet that I have exported from some other program. It
Ok, so I have an excel spreadsheet that contains data that I would like
Currently, I have an Excel spreadsheet with some data and a command button that
I have an excel spreadsheet which contains addresses. I'm reading the data from the
I have some code that takes input from and excel spreadsheet and imports it
I have a script that pulls data out of an excel spreadsheet using the
I have a excel spreadsheet that contains a bunch of columns. My first column
I have a spreadsheet that is using the WORKDAY() function in Excel (which I
I have an excel spreadsheet that contains entire addresses packed in a single cell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.