0

I am trying to import a csv file into the jupyter notebook using the following syntax

time_taken=pd.read_csv("C:\Users\intarvo\Desktop\complaints_data.csv")

But whenever I use this syntax there is an error message occurring

File "<ipython-input-37-85ee89655ddb>", line 1
time_taken=pd.read_csv("C:\Users\intarvo\Desktop\complaints_data.csv")
                      ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape 

As indicated in some of the documents where people faced similar errors I tried using the other slash but unfortunately even that did not work.

I also used

time_taken=open(r'''C:/Users/intarvo/Desktop/complaints_data.csv''')  

but when I try reading time taken, it raises an error

<_io.TextIOWrapper name='C:/Users/intarvo/Desktop/complaints_data.csv' mode='r' encoding='cp1252'>

Can someone please suggest how this error can be resolved?

Neuron
  • 5,141
  • 5
  • 38
  • 59
Swati Kanchan
  • 99
  • 2
  • 15
  • https://stackoverflow.com/questions/2953834/windows-path-in-python check this question as your problem probably comes from the windows paths – JuR Nov 09 '21 at 12:27

4 Answers4

0

pd.read_csv by default uses utf encoding. It seems that your file has some characters that does not belong to utf encoding. So it was not able to parse your file.

Refer to this Question

It seems that your file has cp1252 encoding. You could try:

pd.read_csv('C:/Users/intarvo/Desktop/complaints_data.csv',
             encoding = "ISO-8859-1")
Vardan
  • 152
  • 1
  • 5
0

Please check the file type that saved it as is the csv format.

file_type = pd.read_csv("c:\\file_name\.csv')

It should work.

Neuron
  • 5,141
  • 5
  • 38
  • 59
0
file_type = pd.read_csv(r"c:\\file_name\.csv")

Use r before file path and it will work. Recently I got this error and solved it with this method.

Neuron
  • 5,141
  • 5
  • 38
  • 59
0

What worked for me is taking the file you want to open and opening it into sublime text, copying all the data and then saving it into another sublime text file in the format '.ipynb' then save that in the same directory as your jupyter file, and you should be able to open it normally.

Hope that helps!