cdn网站加速,台州网站建设方案优化,公司网站开发怎么收费,男女做羞羞事试看网站基本想法 
遍历文件夹并从中找到文件名称符合我们需求的多个.txt格式文本文件#xff0c;并从每一个文本文件中#xff0c;找到我们需要的指定数据#xff0c;最后得到所有文本文件中我们需要的数据的集合 
举例 
如现有名为file一个文件夹#xff0c;里面含有大量的.txt格…基本想法 
遍历文件夹并从中找到文件名称符合我们需求的多个.txt格式文本文件并从每一个文本文件中找到我们需要的指定数据最后得到所有文本文件中我们需要的数据的集合 
举例 
如现有名为file一个文件夹里面含有大量的.txt格式文本需要从文件名中找到含有test字段的文件并且取出name是李四、李五、王五的用户数据。 
代码示例 
# -*- coding: utf-8 -*-import os
import pandas as pddef concat_data(ori_path, target_list):result_df  pd.DataFrame()for file in os.listdir(ori_path):if file.endswith(.txt) and file[0:4]  test:file_path  os.path.join(ori_path, file)df  pd.read_csv(file_path, delimiter\t)# try:select_df  df[df[Name].isin(target_list)]data_append  select_dfif not data_append.empty:result_df  pd.concat([result_df, data_append])# except:#     pass# result_df.reset_index(dropFalse, inplaceTrue).drop([index], axis1)result_df.to_csv(ori_path  /result.csv, encodingANSI)return result_dfif __name__  __main__:f_path  rD:\programf_var  [李四, 李五, 王五]concat_data(f_path, f_var)原始数据 结果展示