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

前端 未结 11 2490
庸人自扰
庸人自扰 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:41

    Keeping things tidy with f-strings:

    import os
    import pandas as pd
    
    data_files = '../data_folder/'
    csv_name = 'data.csv'
    
    pd.read_csv(f"{data_files}{csv_name}")
    

提交回复
热议问题