I have been trying to set The Desktop as my working Directory, so I can load a csv
import os
path="/Users/HOME/Desktop"
os.getcwd()
It returns
/
using pandas library I'm failing to use
DF = pd.read_csv("filename", "mode")
I have been trying to set The Desktop as my working Directory, so I can load a csv
import os
path="/Users/HOME/Desktop"
os.getcwd()
It returns
/
using pandas library I'm failing to use
DF = pd.read_csv("filename", "mode")
You did not actually change the working directory, you merely assigned a path to a variable. You need to invoke os.chdir()
with that path (see https://stackoverflow.com/a/431715/14015737):
import os
path="/Users/HOME/Desktop"
os.chdir(path)
os.getcwd()
This should return the path.
In order to then read your .csv
file that is located there (e.g. /Users/HOME/Desktop/test.csv
) you can call read_csv()
without a path. Full example:
import os
import pandas
path='/Users/HOME/Desktop'
os.chdir(path)
df = pandas.read_csv('test.csv')