-1

trying to import a csv file from my desktop

df = pd.read_csv('C:\Users\u1703025\Desktop\Debts.csv',sep =',')

Getting this error

runfile('C:/Users/u1703025/.spyder-py3/temp.py', wdir='C:/Users/u1703025/.spyder-py3')
  File "C:\Users\u1703025\.spyder-py3\temp.py", line 2
    df = pd.read_csv('C:\Users\u1703025\Desktop\Debts.csv',sep =',')
                                                          ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
  • This has **nothing to do with** reading CSV. The problem is already in the part where you try to give the path to the file. It happens because the `\U` and `\u` parts have special meaning inside a string literal. Please read the linked duplicate for more. Also, what you are trying to do is **not called** "importing". It is important to understand proper terminology for things, in order to be able to search for information yourself. – Karl Knechtel Dec 05 '22 at 13:32
  • 1
    Unless you are *specifically* asking about how to solve a cross-version compatibility problem (in which case your question should obviously describe that problem) you should not mix the [tag:python-2.7] and [tag:python-3.x] tags. – tripleee Dec 05 '22 at 13:54

2 Answers2

0

Try this:

df = pd.read_csv('C:\\Users\\u1703025\\Desktop\\Debts.csv',sep =',')
Cow
  • 2,543
  • 4
  • 13
  • 25
0

Just put r before path

pd.read_csv(r'C:\Users\u1703025\Desktop\Debts.csv',sep =',')