12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import datetime
- import multiprocessing
- import os
- import sys
- import pandas as pd
- sys.path.insert(0, os.path.abspath(__file__).split("tmp_file")[0])
- from utils.file.trans_methods import read_file_to_df, read_excel_files
- # read_dir = r'/data/download/collection_data/1进行中/张崾先风电场-陕西-华电/清理数据/点检表以外测点儿-20241209'
- # save_dir = r'/data/download/collection_data/1进行中/张崾先风电场-陕西-华电/清理数据/变桨-20241210'
- # user_cols = ['Time', '机舱外温度', '桨叶角度A', '桨叶角度B', '桨叶角度C',
- # '轴1电机电流', '轴2电机电流', '轴3电机电流',
- # '轴1电机温度', '轴2电机温度', '轴3电机温度']
- read_dir = r'/data/download/collection_data/1进行中/张崾先风电场-陕西-华电/清理数据/点检表以外测点儿-20241210'
- save_dir = r'/data/download/collection_data/1进行中/张崾先风电场-陕西-华电/清理数据/偏航-20241210'
- user_cols = ['Time', '实际风速', '偏航误差', '电缆扭角', '激活偏航解缆阀','激活顺时针偏航','激活逆时针偏航']
- os.makedirs(save_dir, exist_ok=True)
- def read_and_save(file_path, read_dir, save_dir):
- begin = datetime.datetime.now()
- df = read_file_to_df(file_path, read_cols=user_cols)
- df['Time'] = pd.to_datetime(df['Time'], errors='coerce')
- df.sort_values(by=['Time'], inplace=True)
- df.to_csv(os.path.join(save_dir, os.path.basename(file_path)), index=False, encoding='utf8')
- print(os.path.basename(file_path), '耗时:', (datetime.datetime.now() - begin))
- if __name__ == '__main__':
- begin = datetime.datetime.now()
- all_files = read_excel_files(read_dir)
- with multiprocessing.Pool(16) as pool:
- pool.starmap(read_and_save, [(file, read_dir, save_dir) for file in all_files])
- print('总耗时:', (datetime.datetime.now() - begin))
|