Loop through multiple CSV files and run a script

后端 未结 4 1310
故里飘歌
故里飘歌 2021-01-28 16:40

I have a script which pulls in data from a csv file, does some manipulations to it and creates an output excel file. But, its a tedious process as I need to do it for multiple f

4条回答
  •  鱼传尺愫
    2021-01-28 17:02

    try this:

    import glob
    
    files = glob.glob(INPUT_PATH + "*.csv")
    
    for file in files:
        # Get data
        df = pd.read_csv(file)
    
        # Clean data
        #your cleaning code  
    
       # Push to excel
       writer = pd.ExcelWriter(OUTPUT_PATH + file.split("/")[-1].replace(".csv","_OUTPUT.xlxs", engine='xlsxwriter')
    

提交回复
热议问题