Python:如何读取文件

时间:2018-01-31 03:03:40

标签: python

每当我尝试读取csv文件时,都会收到此消息!

import pandas as pd
read = pd.read_csv('C:\Users\Devika\Desktop\New.csv')
  File "<ipython-input-12-15a303f06c16>", line 1
    read = pd.read_csv('C:\Users\Devika\Desktop\New.csv')
                  ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

我犯了什么愚蠢的错误吗?

1 个答案:

答案 0 :(得分:1)

试试这个

read = pd.read_csv(r'C:\Users\Devika\Desktop\New.csv')

或者如果那不起作用

import os
cfile=os.path.join(r'C:\Users\Devika\Desktop','New.csv')
read = pd.read_csv(cfile)