A Question about loading csv file with python

Hello:



I m actually learning hwo to  work with data with Phyton, and I noticed something:



I actualy downloaded a csv data file from https://www.nseindia.com, and I tried to run the following code in Spyder:



import numpy as np

import pandas as pd

infy = pd.read_csv ('C:\Users\Ghery Jorge Cardenas\Desktop\infosys.csv')





Bue I got this error:





SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape



Can you please help me with this?



Thanks

There are two ways to do this you can either keep the file directly in the place where you python file is and acces the file with its file name and extension. 

 

In Python, backslash is used to signify special characters.
 
Second you have used "\" instead use "/" that will work. or "\\" will also work .

or you can use  infy = pd.read_csv (r'C:\Users\Ghery Jorge Cardenas\Desktop\infosys.csv')

just add an r like i have donein the above in your path.Hope this helps.

 

Hi Ghery,



This is because you are using '' which is treated as escape char in python. You can add 'r' (for raw) to read the file or add another '&#39



infy = pd.read_csv (r'C:\Users\Ghery Jorge Cardenas\Desktop\infosys.csv')



or 



infy = pd.read_csv ("C:\Users\Ghery Jorge Cardenas\Desktop\infosys.csv")