import os import pandas as pd import numpy as np path =r"/**/**/**" #填上文件所在的目录 file_name = [] frames = [] for root,dirs,files in os.walk(path): #遍历根目录下的每一个文件 for file in files: if file[-7:]== '_qc.tsv': #这里是选取后缀为qc.tsv的文件 file_name.append(file) df = pd.read_csv(os.path.join(root,file),sep='\t') #将excel导入数据库,如需跳过行在skiprows中体现 df['type'] = (file.split('/')[-1]).split('.')[-2] frames.append(df) else: continue df1 = pd.concat(frames,sort=True,ignore_index=True)#重新设置索引
标签:file,后缀,Python,pd,frames,import,csv From: https://www.cnblogs.com/YlnChen/p/16640342.html