Error while trying to import pandas data into Jupyter Notebook

Asked

Viewed 204 times

0

I am trying to import data using pandas, but I always get the following error:

File "<ipython-input-15-fb05c39e0291>", line 1
    temperaturasDasCidades = pd.read_csv("C:\Users\lopes\Desktop\brutos\temperatura_global\city_temperature.csv", sep=";", encoding='ISO-8859-1')
                                                                                                                ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape 

The encoding and separator are correct, as well as the path where my csv file for reading the data is also. I have tried to duplicate the counterbars or invert them to bars, as well as tried to put the r at first to turn into a raw string.

  • Is the file really in csv format? Or you just changed the extension?

  • you can put here the first 10 files?

  • 1

    It seems that the error is in the call. Instead of C:\Users\lopes\... use C:\\Users\\lopes\\... "escaping" the counter-bar.

  • Roger, the file is in csv format even

  • It worked, Paul, thank you

1 answer

0

You can either do as Paul said, putting double inverted bars, or add one r before the string.

temperaturasDasCidades = pd.read_csv(r"C:\Users\lopes\Desktop\brutos\temperatura_global\city_temperature.csv", sep=";", encoding='ISO-8859-1')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.