(unicode error) 'unicodeescape' codec can&

2019-01-02 20:29发布

I'm trying to read an csv file into python (spyder) but I keep getting an error. My code looks as follows:

import csv

data = open("C:\Users\miche\Documents\school\jaar2\MIK\2.6\vektis_agb_zorgverlener")
data = csv.reader(data)  
print(data)

and I get the following error:

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

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. I hope someone can tell me what I have to do.. Thanks in advance

8条回答
长期被迫恋爱
2楼-- · 2019-01-02 21:13

Just putting an r in front works well.

eg:

  white = pd.read_csv(r"C:\Users\hydro\a.csv")
查看更多
听够珍惜
3楼-- · 2019-01-02 21:17

it worked for me by neutralizing the '\' by f = open('F:\\file.csv')

查看更多
登录 后发表回答