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