unicode error unicodeescape codec can t decode bytes in position 2-3 truncated UXXXXXXXX escape

0 votes
import pandas as pd
data=pd.read_csv("C:\Users\Welcome\Desktop\Sales.csv",encoding='latin1')
print(data.head())
Dec 29, 2019 in Python by Abhishek
• 120 points
100,851 views

3 answers to this question.

+5 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
• 52,350 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.

And, another method could be to simply replace all the back slashes with forward slashes in the address and all other things same.  :)

(Both of them do work for me.)
Thanks that help
Thanks from my side too
+2 votes

This error occurs because you are using a normal string as a path. You can use one of the three following solutions to fix your problem:

1: Just put r before your normal string it converts normal string to raw string:

pandas.read_csv(r"C:\Users\DeePak\Desktop\myac.csv")

2:

pandas.read_csv("C:/Users/DeePak/Desktop/myac.csv")

3:

pandas.read_csv("C:\\Users\\DeePak\\Desktop\\myac.csv")
answered Dec 16, 2020 by Roshni
• 10,520 points
0 votes

Solution 1: Add a “r” character in the beginning of string. in Python, when we add a “r” character, it's meaning a complete string. Solution 2: Change “\” to be “/”. Solution 3: Change “\” to be “\\”.

You should use a raw string to avoid such behaviour (r"xxx")

tables = camelot.read_pdf(r"C:\Users\stanleychen\Desktop\MR2-PL1.pdf")
answered Dec 16, 2020 by Gitika
• 65,890 points

Related Questions In Python

0 votes
1 answer

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

This error occurs because you are using ...READ MORE

answered Sep 9, 2020 in Python by Gitika
• 65,890 points
14,018 views
0 votes
0 answers
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 28, 2018 in Python by Nabarupa Das
2,901 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
13,818 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,391 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,994 views
+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
2,378 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
• 52,350 points
2,079 views
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