import multiprocessing import os import sys sys.path.insert(0, os.path.abspath(__file__).split("tmp_file")[0]) from utils.file.trans_methods import read_file_to_df, create_file_path def read_and_save(file_path, select_cols, save_path): base_name = os.path.basename(file_path).split('.')[0] df = read_file_to_df(file_path, read_cols=select_cols) save_path = os.path.join(save_path, base_name + '.csv') create_file_path(save_path, True) df.to_csv(save_path, index=False, encoding='utf-8') if __name__ == '__main__': select_cols_str = 'Time,瞬时风速,风机号,瞬时功率,扭矩给定,扭矩反馈,高风切出,风机允许功率管理,功率管理使能反馈,不可利用,功率曲线可用,主控初始化完成,待机,启动,偏航,并网,限功率,正常发电,故障,紧急停机,快速停机,正常停机,告警,停机完成,允许功率管理,处于功率管理,检修,维护' select_cols = [i for i in select_cols_str.split(',') if i] read_dir = r'/data/download/collection_data/1进行中/张崾先风电场-陕西-华电/清理数据/20241213(26,38)完整字段/26' save_dir = r'/data/download/collection_data/1进行中/张崾先风电场-陕西-华电/清理数据/20241213(26,38)完整字段/20241216113130' with multiprocessing.Pool(6) as pool: pool.starmap(read_and_save, [(os.path.join(read_dir, i), select_cols, save_dir) for i in os.listdir(read_dir)])