Import multiple csv files into pandas and concatenate into one DataFrame

前端 未结 16 2122
既然无缘
既然无缘 2020-11-21 07:47

I would like to read several csv files from a directory into pandas and concatenate them into one big DataFrame. I have not been able to figure it out though. Here is what I

16条回答
  •  天命终不由人
    2020-11-21 07:48

    You can do it this way also:

    import pandas as pd
    import os
    
    new_df = pd.DataFrame()
    for r, d, f in os.walk(csv_folder_path):
        for file in f:
            complete_file_path = csv_folder_path+file
            read_file = pd.read_csv(complete_file_path)
            new_df = new_df.append(read_file, ignore_index=True)
    
    
    new_df.shape
    

提交回复
热议问题