How to open my files in data_folder with pandas using relative path?

前端 未结 11 2489
庸人自扰
庸人自扰 2020-12-22 23:40

I\'m working with pandas and need to read some csv files, the structure is something like this:

folder/folder2/scripts_folder/script.py

folder/fol

11条回答
  •  误落风尘
    2020-12-23 00:43

    This link here answers it. Reading file using relative path in python project

    Basically using Path from pathlib you'll do the following in script.py

    from pathlib import Path
    path = Path(__file__).parent / "../data_folder/data.csv"
    pd.read_csv(path)
    

提交回复
热议问题