使用网页版jupyder在读取桌面文件时,刚开始我的代码是:
baseball = pd.read_csv('C:UsersTuZhiqiangDesktop
esult.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:UsersTuZhiqiangDesktop
esult.csv')
print(baseball)
结果正常: