Klue Klue - 5 months ago 45
Python Question

URLError: urlopen error [Errno 2] No such file or directory

I was perfectly able to use pandas

read_csv
for reading files in Windows. However I cannot figure out how to set local path in Ubuntu?

If I do this:

data = pd.read_csv(r'file://home/gosper/Desktop/test.csv')


... it throws the error:
URLError: <urlopen error [Errno 2] No such file or directory

Answer

this should work for Windows's and UNIX's Desktop folder:

data = pd.read_csv(os.path.expanduser('~') + '/Desktop/test.csv')