筛选字段.py 1.4 KB

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