...

Pandas读取多个csv文件

直接上代码,主要使用pd.concat来拼接数据帧

file_dir = "./data_set"  # file directory
all_csv_list = os.listdir(file_dir)  # get csv list
for single_csv in all_csv_list:
    single_data_frame = pd.read_csv(os.path.join(file_dir, single_csv))
#     print(single_data_frame.info())
    if single_csv == all_csv_list[0]:
        all_data_frame = single_data_frame
    else:  # concatenate all csv to a single dataframe, ingore index
        all_data_frame = pd.concat([all_data_frame, single_data_frame], ignore_index=True)
posted @ 2022-04-09 12:35  韩志超  阅读(365)  评论(0编辑  收藏  举报