python – (unicode error) unicodeescape codec cant decode bytes in position 2-3: truncated UXXXXXXXX escape

python – (unicode error) unicodeescape codec cant decode bytes in position 2-3: truncated UXXXXXXXX escape

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(rC:UsersDeePakDesktopmyac.csv)

2:

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

3:

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

The first backslash in your string is being interpreted as a special character, in fact because its followed by a U its being interpreted as the start of a unicode code point.

To fix this you need to escape the backslashes in the string. I dont know Python specifically but Id guess you do it by doubling the backslashes:

data = open(C:\Users\miche\Documents\school\jaar2\MIK\2.6\vektis_agb_zorgverlener)

python – (unicode error) unicodeescape codec cant decode bytes in position 2-3: truncated UXXXXXXXX escape

You can just put r in front of the string with your actual path, which denotes a raw string. For example:

data = open(rC:UsersmicheDocumentsschooljaar2MIK2.6vektis_agb_zorgverlener)

Leave a Reply

Your email address will not be published.