将不同文件夹下的CSV文件合并在不同文件夹下

import os
import pandas as pd
# 将不同文件下的多个csv按顺序合并在一起
files = os.listdir("/home/shuaishuai/文档/实验数据/行为识别/snippets/feature")
files.sort()
for file in files:
    path1 = os.path.join('/home/shuaishuai/文档/实验数据/行为识别/snippets/feature'+'/'+file)
#     print(path1)
    for filepath,dirnames,filenames in os.walk(path1):
#         dirnames.sort()
# #         print(dirnames)
        filenames.sort()
#         print(filenames)
        for filename in filenames:
            path = os.path.join(filepath+'/'+filename)
#             print(path)
            fl = pd.read_csv(path, header = None)
            fl.to_csv("/home/shuaishuai/文档/实验数据/行为识别/snippets/total_feature/"+file+".csv", mode='a', index=False, header=False)

# 将不同文件夹下的CSV文件合并在不同文件夹下

你可能感兴趣的:(pandas,python)