Pandas reading csv files with partial wildcard

后端 未结 4 1752
天涯浪人
天涯浪人 2021-01-05 13:45

I\'m trying to write a script that imports a file, then does something with the file and outputs the result into another file.

df = pd.read_csv(\'somefile2018.

4条回答
  •  情深已故
    2021-01-05 14:35

    You can get the list of the CSV files in the script and loop over them.

    from os import listdir
    from os.path import isfile, join
    mypath = os.getcwd()
    
    csvfiles = [f for f in listdir(mypath) if isfile(join(mypath, f)) if '.csv' in f]
    
    for f in csvfiles:
        pd.read_csv(f)
    # the rest of your script
    

提交回复
热议问题