Python

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

ZA Asked by Zahir · 12-08-2020
0 upvotes 467 views 3 comments
The question

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

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

3 comments

MA
27-09-2020
Thanks... It really helped for me.
RO
19-10-2020
Thanks. it worked for me
MA
05-11-2020
It worked thanks you so much for provide solution

5 answers

0
RO
Answered on 25-10-2020

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())
BA 02-12-2021

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

AA 04-11-2021

Thank you so much you saved me

0
RO
Answered on 21-01-2021
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.
0
RA
Answered on 09-02-2021
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:
0
AM
Answered on 16-02-2021
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
0
MA
Answered on 11-01-2022
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.

Share your thoughts

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

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"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.

Book Free Session