I have a folder with a few subfolders as here:
my-project/
input/
data.csv
src/
script.py
I want to read data from my-project/input/data.csv
within script.py
, so I have:
import pandas as pd
data = pd.read_csv('../input/data.csv')
However, my workspace is my-project
so when I run script.py
it returns:
Exception has occurred: FileNotFoundError [Errno 2] No such file or directory: '../input/data.csv
which is understandable as input
is within my-project
, not at the same level. However, referring with ..
really feels like the correct way to refer to data.csv
as we do it from script.py
. But maybe I'm wrong?
In case this is a reasonable way to refer to my data file - how can I setup the VSCode to be able to run the script without returning the error? I think there should be a way to add the subfolder to searching path, without needing to open the subfolder as a workspace, but I had a bad luck trying to find it.
@Edit: Please note that I'm aware of the concept of relative/absolute paths. This questions is more about VSCode settings. I am also willing to accept the answer: "No, referring with ../input/data.csv
is the dumb thing to do in this settings. You should refer with input/data.csv
instead, because..." (it's contradictory with my current understanding, but I could be entirely wrong and I'd be happy to learn a different point of view)