(unicode 错误)“unicodeescape"编解码器无法解码位置 2-3 中的字节:截断的 UXXXXXXXX 转义 [英] (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape
问题描述
我正在尝试将 .csv 文件读入 Python (Spyder),但我一直收到错误消息.我的代码:
I'm trying to read a .csv file into Python (Spyder) but I keep getting an error. My code:
import csv
data = open("C:UsersmicheDocumentsschooljaar2MIK2.6vektis_agb_zorgverlener")
data = csv.reader(data)
print(data)
我收到以下错误:
SyntaxError: (unicode error) 'unicodeescape' 编解码器无法解码字节在位置 2-3:截断 UXXXXXXXX 转义
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape
我尝试用 或/替换 并且我尝试在 "C.. 之前放一个 r 但所有这些都不起作用.
I have tried to replace the with or with / and I've tried to put an r before "C.. but all these things didn't work.
推荐答案
出现此错误是因为您使用的是普通字符串作为路径.您可以使用以下三种解决方案之一来解决您的问题:
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:只需将 r
放在普通字符串之前,它会将普通字符串转换为原始字符串:
1: Just put r
before your normal string it converts normal string to raw string:
pandas.read_csv(r"C:UsersDeePakDesktopmyac.csv")
2:
pandas.read_csv("C:/Users/DeePak/Desktop/myac.csv")
3:
pandas.read_csv("C:\Users\DeePak\Desktop\myac.csv")
这篇关于(unicode 错误)“unicodeescape"编解码器无法解码位置 2-3 中的字节:截断的 UXXXXXXXX 转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!