Python: UnicodeDecodeError: "utf-8" codec can"t decode byte 0xa0 in position 10: invalid start byte

+1 vote

Unable to import this file it shows an error. My code was:

import pandas as pd
a = pd.read_csv("filename.csv")
Jul 11, 2019 in Python by Yadu
28,358 views

1 answer to this question.

+5 votes
Best answer

You have to use the encoding as latin1 to read this file as there are some special character in this file, use the below code snippet to read the file. Try this:

import pandas as pd
data=pd.read_csv("C:\\Users\\akashkumar\\Downloads\\Customers.csv",encoding='latin1')
print(data.head())
answered Jul 11, 2019 by Ritu

selected Dec 11, 2019 by Kalgi
Thank you. Worked well for me ....
Glad to hear it :)

Please upvote.

thanks. it worked. 

encoding='latin1' part solved my problem.
thanks worked well
Why does it work ?
Hey guys, how's the corona Quarantine going on? You guys working from home too?
Hey, @Book

It will help if you could just elaborate on your doubt.
Thank you..:) bro
>>> file = open('policydocs/policy/0_policy_Test Backoffice.pdf', encoding='latin1')
>>> result = k.set_contents_from_file(file)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "D:\treatufair\venv\lib\site-packages\boto\s3\key.py", line 1307, in set_contents_from_file
    self.send_file(fp, headers=headers, cb=cb, num_cb=num_cb,
  File "D:\treatufair\venv\lib\site-packages\boto\s3\key.py", line 760, in send_file
    self._send_file_internal(fp, headers=headers, cb=cb, num_cb=num_cb,
  File "D:\treatufair\venv\lib\site-packages\boto\s3\key.py", line 957, in _send_file_internal
    resp = self.bucket.connection.make_request(
  File "D:\treatufair\venv\lib\site-packages\boto\s3\connection.py", line 667, in make_request
    return super(S3Connection, self).make_request(
  File "D:\treatufair\venv\lib\site-packages\boto\connection.py", line 1070, in make_request
    return self._mexe(http_request, sender, override_num_retries,
  File "D:\treatufair\venv\lib\site-packages\boto\connection.py", line 939, in _mexe
    response = sender(connection, request.method, request.path,
  File "D:\treatufair\venv\lib\site-packages\boto\s3\key.py", line 895, in sender
    raise provider.storage_response_error(
boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>BadDigest</Code><Message>The Content-MD5 you specified did not match what we received.</Message><ExpectedDigest>4a5e3dabb8dd3747f239ddf71050f327</ExpectedDigest><
CalculatedDigest>1NIHgiuwNo7w3xjQKn7WLg==</CalculatedDigest><RequestId>485E4F3BD00D8865</RequestId><HostId>tFC75KSl6s4bTxW3WFcTPUUfxNmvhOMrWYPn7dfnRlPXlxI0X15zyvYZAEgLO/EsUBe4
0BEtMIc=</HostId></Error>
>>> file = open('policydocs/policy/0_policy_Test Backoffice.pdf', encoding="utf-8")

Thank you. it worked for me too.

Related Questions In Python

0 votes
0 answers

utf-8' codec can't decode byte 0xa0 in position 10: invalid start byte

my code import wordcloud import numpy as np from matplotlib ...READ MORE

Mar 29 in Python by anonymous
• 120 points
432 views
0 votes
1 answer

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 16: invalid start byte

Hi@akhtar, This type of error will occur, if ...READ MORE

answered Apr 9 in Python by MD
• 21,340 points
567 views
+1 vote
3 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

The error message invalid literal for int() ...READ MORE

answered Apr 29 in Python by warrenfelsh
• 140 points
71,564 views
0 votes
2 answers

Error: Speech to Text Codec cannot decode the bytes in position

import speech_recognition as sr r = sr.Recognizer() audio ='C\Users\Desktop\audiofile1.wav' with ...READ MORE

answered Nov 27, 2018 in Python by Nabarupa Das
526 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 929 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer
+1 vote
1 answer

UnicodeDecodeError: "utf-8" codec can't decode byte in position : invalid start byte

You have to use the encoding as latin1 ...READ MORE

answered Jul 23, 2019 in Python by Kunal
27,427 views