How to overcome Unicode error?

Screen Link:
https://app.dataquest.io/m/349/project%3A-learn-and-install-jupyter-notebook/7/text-and-markdown-cells

My Code:
opened_file = open(‘C:\Users\ctpat\Downloads\AppleStore.csv’, encoding=‘utf8’)

from csv import reader
read_file= reader(opened_file)
apps_data = lilst(read_file)
apps_data[:4]


What I expected to happen:
After providing the file path, i encountered with Unicode error, so i did as suggested in instructions, but still got the below mentioned error. I expected it to run error less.
Also i think its better to load .csv files using pandas instead of reader, appreciate your thoughts regarding it.

What actually happened:

File “”, line 1
opened_file = open(‘C:\Users\ctpat\Downloads\AppleStore.csv’, encoding=‘utf8’)
^
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape


<!--Enter other details below: -->

I tried to open the dataset from same location using 

import pandas as pd
apps_data= pd.read_csv("C:\\Users\ctpat\Downloads\AppleStore.csv", encoding='utf8')

and it worked in the jupyter notebook i opened from anaconda, but when i tried the same code into the mision embedded jupyter notebook, it did'nt work, and threw same error. I wonder why?

Correct the slashes to forward slashes (/) in “opened_file” .

Below is the code line:

opened_file = open(“C:/Users/ctpat/Download/AppleStore.csv”, encoding=“utf8”)

Thanks for reply pablajaspreet94, I tried that too, but it comes up with

FileNotFoundError: [Errno 2] No such file or directory: ‘C:/Users/ctpat/Downloads/AppleStore.csv’

I have the AppleStore.csv downloaded in downloads, do i need to move it somewhere in order for jupyter to recognize it?

One of the approaches listed here should help resolve your problem - https://stackoverflow.com/a/46011113

Try double backslash then.

Thanks the_doctor but i tried them all, with raw strings and with double backlashes and all but still did not work. :pensive:

Tried it, did not work either.

Have you tried using different encodings other than UTF-8.

No did not try that but i also have an error of file not found! No idea how to resolve it! Do i need to move my csv file elsewhere?
I tried to open the dataset from same location using

import pandas as pd
apps_data= pd.read_csv(“C:\Users\ctpat\Downloads\AppleStore.csv”, encoding=‘utf8’)

and it worked in the jupyter notebook i opened from anaconda, but when i tried the same code into the mision embedded jupyter notebook, it did’nt work, and threw same error. I wonder why?

If you are trying to run in the Data Quest embedded jupyter notebook, then there is no need to specify the path. It is already present on the server, just mention the filename and encoding.

This will work.

1 Like

Oh Okay let me try it, but should not it work with path too?

pablajaspreet94 It worked, thanks for the time and help. :relaxed:

This embedded one is set by DQ. So, they are linked to the file automatically. They have not provided the rights to set the path from offline machine.

It would be great if you could please mark answer I have provided as solution. :smile:

`

It is important to mark the right answer as solution, so users that come to this topic with the same question as you, can easily see the solution for it.

`

1 Like