遍历文件夹下的csv,把数据读进一张表

import pandas as pd
import os

if __name__ == '__main__':
    Path = 'c:\checklog'

    dfs = []
    for dir_path, dir_names, file_names in os.walk(Path):
        for f in file_names:
            if f.find('cpu_mem.csv') != -1:
                full_path = os.path.join(dir_path, f)
                print(full_path)
                if os.path.getsize(full_path):
                    dfs.append(pd.read_csv(full_path, header=None))

    df = pd.concat(dfs, sort=False)
    df.to_excel('c:\checklog\out.xlsx')
posted @ 2019-08-08 21:40  东宫得臣  阅读(586)  评论(0编辑  收藏  举报