data_pre_xiaopeng.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import os
  2. import pandas as pd
  3. # 定义文件夹路径
  4. def data_get(folder_path, algo_pack_param):
  5. # 获取文件夹中的所有文件和文件夹
  6. # all_files = os.listdir(folder_path)
  7. all_data = pd.read_csv(f"{folder_path}")
  8. # for file in all_files:
  9. # df = pd.read_excel(f"{folder_path}/{file}")
  10. # if not df.empty:
  11. # all_data = all_data.append(df, ignore_index=True)
  12. try:
  13. all_data1 = all_data[all_data['time']<'2024-09-01 00:00:00']
  14. # all_data2 = all_data[all_data['time']>='2024-09-01 00:00:00']
  15. # all_data2['time'] = all_data2['time'].apply(lambda x: '2024' + x[4:0])
  16. all_data1['time'] = pd.to_datetime(all_data1['time'], format='%Y-%m-%d %H:%M:%S')
  17. print(f"长度差:{len(all_data)-len(all_data1)}")
  18. except Exception as e:
  19. print(e)
  20. mask = all_data1['time'].apply(lambda x: isinstance(x, str))
  21. all_data1 = all_data1[~mask]
  22. all_data1['time'] = pd.to_datetime(all_data['time'], format='%Y-%m-%d %H:%M:%S')
  23. all_data1.sort_values(by=['time'], inplace=True)
  24. #数据处理
  25. CellVoltNums = len([col for col in all_data1.columns if 'cellvolt_' in col])
  26. CellTempNums = len([col for col in all_data1.columns if 'celltemp_' in col])
  27. # CellVoltNums=int(algo_pack_param['CellVoltTotalCount'])
  28. # CellTempNums = int(algo_pack_param['CellTempTotalCount'])
  29. cellvolt_name=['cell_voltage'+str(x) for x in range(1, CellVoltNums+1)]
  30. celltemp_name=['cell_temp'+str(x) for x in range(1, CellTempNums+1)]
  31. all_data1.columns = ['vin','timer','time','speed','bms_sta','chgmode','pack_volt','pack_crnt','odo','pack_soc','pack_soh',
  32. 'remainenergy','insulation_resistance','cell_volt_max','cell_volt_min','max_vol_num','min_vol_num',
  33. 'cell_temp_max','cell_temp_min','max_temp_num','min_temp_num'] + cellvolt_name + celltemp_name + \
  34. ['ds']
  35. return all_data1, cellvolt_name, celltemp_name