In my Python script main.py, I read a csv using pandas like this:
df = pd.read_csv('./input/input.csv')
My setup looks like this:
project/
src/
input/
input.csv
output/
output.csv
main.py
When I try to run my Python script from within the srcfolder, it runs smoothly. However, when I do this from my projectfolder:
python src/main.py
it throws an error
IOError: [Errno 2] No such file or directory: './input/input.csv'
What am I missing out on? It's literally the same script
With this code you can call main.py from the project folder (
python src/main.py). If you have other needs, simply change your working dir with os.chdir().