Request a Call Back

UnicodeDecodeError utf-8 codec cannot decode byte 0x87 in position 10 invalid start byte


I am unable to import this file it showing an error :

import pandas as pd  a = pd.read_csv("xyz.csv")

   2020-08-12 in Python by Zahir | 319,591 Views


  • Thanks... It really helped for me.

       Commented 2020-09-27 by Mala

  • Thanks. it worked for me

       Commented 2020-10-19 by Roman

  • It worked thanks you so much for provide solution

       Commented 2020-11-06 by Manohar


Write a Comment

Your email address will not be published. Required fields are marked (*)



All answers to this question.


def decode(self, input, final=False):
# Decode the input while considering the buffer data = self.buffer + input (result, consumed) = self._buffer_decode(data, self.errors, final)
# Retain any undecoded input for the next invocation self.buffer = data[consumed:]
return result
I am encountering a similar error and I am relatively new to this. How can I resolve it?
Error:
File "./load_dap_templates_dave.py", line 284, in data = pickle.load(neFile) File
"/usr/local/lib/python3.7/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

Thank you in advance.

   Answered 2022-01-11 by Manoj


Python bytes decode() function is used to convert bytes to string object. Both these functions allow us to specify the error handling scheme to use for encoding/decoding errors. The default is 'strict' meaning that encoding errors raise a UnicodeEncodeError.
The UnicodeDecodeError normally happens when decoding an str string from a certain coding. Since codings map only a limited number of str strings to unicode characters, an illegal sequence of str characters will cause the coding-specific decode() to fail

   Answered 2021-02-16 by Aman


str = unicode(str, errors='replace')  

or

str = unicode(str, errors='ignore')  

Note:This will strip out (ignore) the characters in question returning the string without them.

For me this is ideal case since I'm using it as protection against non-ASCII input which is not allowed by my application.

Alternatively:Use the open method from the codecs module to read in the file:

import codecs with codecs.open(file_name, 'r', encoding='utf-8',                   errors='ignore') as fdata:

   Answered 2021-02-09 by Ramu


Prompt solution Avoid arbitrary decoding and encoding of strings. Do not take for granted that your strings are encoded in UTF-8. Aim to convert strings to Unicode as early as possible in your code. Address your locale settings: How can you resolve UnicodeDecodeError in Python 3.6? Refrain from resorting to quick reload workarounds. Eager to harness the potential of data? Enroll in our Data Science with Python Course to acquire the skills necessary for data analysis, visualization, and informed decision-making.

   Answered 2021-01-21 by Rohit


To properly read this file, it is necessary to utilize the latin1 encoding due to the presence of special characters. Please refer to the code snippet below for guidance on how to read the file. Consider trying this approach:

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

   Answered 2020-10-25 by Rohit

  • Thank you so much you saved me

       Commented 2021-11-04 by Aarif

  • its really helpful ,its worked thank you for saving my time.

       Commented 2021-12-02 by Babalu


Suggested Questions

How to find index of element in..
Posted 2021-06-14 by iCert Global.
How to download s3 bucket folder?..
Posted 2020-03-16 by iCert Global.
Python AWS Boto3 How do i read..
Posted 2020-03-12 by iCert Global.
How to filter out na in R..
Posted 2020-02-22 by iCert Global.
How to find all the classes of..
Posted 2023-08-11 by iCert Global.
Copying files from host to Docker container..
Posted 2023-08-11 by iCert Global.
how to exit a python script in..
Posted 2022-11-16 by iCert Global.
How to import a jar file in..
Posted 2022-11-16 by iCert Global.

Disclaimer

  • "PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc.
  • "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA.
  • COBIT® is a trademark of ISACA® registered in the United States and other countries.
  • CBAP® and IIBA® are registered trademarks of International Institute of Business Analysis™.

We Accept

We Accept

Follow Us

iCertGlobal facebook icon
iCertGlobal twitter
iCertGlobal linkedin

iCertGlobal Instagram
iCertGlobal twitter
iCertGlobal Youtube

Quick Enquiry Form

watsapp WhatsApp Us  /      +1 (713)-287-1187