0

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")
buddemat
  • 4,552
  • 14
  • 29
  • 49
  • 1
    Please include some more information in which way you are failing to use `read_csv`. What did you enter as filename and mode? What error did you encounter? – buddemat Jan 19 '21 at 13:36

1 Answers1

0

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')
buddemat
  • 4,552
  • 14
  • 29
  • 49