使用网页版jupyder在读取桌面文件时,刚开始我的代码是:
baseball = pd.read_csv('C:\Users\TuZhiqiang\Desktop\result.csv')
print(baseball)
一直报错:
(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
后来发现:
在Python中 \ 是转义符,\u表示其后是UNICODE编码,因此\User在这里会报错,在字符串前面加个 r(rawstring 原生字符串),可以避免python与正则表达式语法的冲突!
修改后:
baseball = pd.read_csv(r'C:\Users\TuZhiqiang\Desktop\result.csv')
print(baseball)
结果正常: