(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

+1 vote
import pandas as pd
data=pd.read_csv("C:\Users\Welcome\Desktop\Sales.csv",encoding='latin1')
print(data.head())
Dec 28, 2019 in Python by Abhishek
• 130 points
4,989 views

1 answer to this question.

+2 votes

You are getting this error because you are using the path to the file as a string. Change that line to something like this:

pandas.read_csv(r"C:\Users\Welcome\Desktop\Sales.csv",encoding='latin1')

Hope it helps :)

answered Dec 31, 2019 by Kalgi
• 51,850 points
Yes it really helped!!...but may i know the interpretaion of keeping r and latin1 at the ends?

Thank you.

Hey, @kamala,

The latin-1 encoding in Python implements ISO_8859-1:1987 which maps all possible byte values the first 256 Unicode code points and thus ensures decoding errors will never occur regardless of the configured error handler.

Related Questions In Python

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
537 views
0 votes
2 answers

Python Error "UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b1' in position 20: ordinal not in range(128)"

import csv import sys reload(sys) sys.setdefaultencoding('utf8') data = [["a", "b", u'\xe9']] with ...READ MORE

answered Jun 28, 2019 in Python by anonymous
3,143 views
+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
29,239 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 in Python by anonymous
• 120 points
475 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 944 views
0 votes
0 answers
+4 votes
6 answers
+7 votes
8 answers

Difference for string comparison in Python: 'is' vs. ==

If we use "==" means both variables ...READ MORE

answered Sep 3, 2018 in Python by Parul Raheja
555 views
0 votes
1 answer

Python error "raise CommandFailedError(args) bench.utils.CommandFailedError: (’–site’, ‘all’, ‘migrate’)"

Install pyopenssl to your python pip install pyopenssl ...READ MORE

answered Aug 5, 2019 in Python by Kalgi
• 51,850 points
156 views