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

+3 votes

While I importing the file it shows

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

Code:

import pandas as pd
a = pd.read_csv("filename.csv")
Jul 23, 2019 in Python by Hari
247,035 views
Beautiful. Thanks, that worked for me. Opening the file in Python and sniffing the encoding gave the wrong one.

2 answers to this question.

+3 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,

import pandas as pd

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

print(data.head())

Also Read: What does the error message utf-8 codec can't decode byte 0xa0 in position 10: invalid start byte indicate?

answered Jul 23, 2019 by Kunal

selected Dec 24, 2019 by Kalgi
Thanks. it is working.

could you explain? What is the reason for this problem and what that "encoding ='latin1' " mean?
Kunal you're awesome! That was driving me mad

Hey, @Brij Mohan,

 "encoding ='latin1' " mean means that dev tools are sourcing the files as latin1 instead of the UTF-8 files that they are. This happens irrespective of the Encoding: UTF-8.

thank you, its works
thanks for saving my day
0 votes

Try using :

pd.read_csv(“Your filename", encoding="ISO-8859-1”)

The code that I parsed from some website was converted in this encoding instead of default UTF-8 encoding which is standard.

answered Dec 10, 2020 by Niroj
• 82,880 points

Related Questions In Python

0 votes
2 answers

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

Thanks, This answer was helpful. READ MORE

answered Jul 11, 2020 in Python by Prashant Chhatrashali
16,576 views
0 votes
1 answer

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

Hi, @hala, Regarding your query, you can go ...READ MORE

answered Jun 29, 2020 in Python by Niroj
• 82,880 points
17,485 views
0 votes
2 answers

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

Hey,  @Himanshu. It's still most likely gzipped data. ...READ MORE

answered Jul 27, 2020 in Python by Gitika
• 65,890 points
24,709 views
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, 2020 in Python by anonymous
• 120 points
5,193 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

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

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,902 views
+5 votes
4 answers
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP