import pandas as pd from sqlalchemy import create_engine import numpy as np def cellVolt_rang(sn,df_bms): #电压排序................................................................................................................................................................ print('--------计算中----------') sn_choose1 = [] temp1 = pd.DataFrame() df_temp_crnt = df_bms[df_bms['current']>1]#筛选充电数据 df_temp = df_temp_crnt[df_temp_crnt['position']==2]#筛选充电数据 if not df_temp.empty: df_chrgr = df_temp.reset_index(drop=True) df_chrgr_cellvolt = df_chrgr[['cellvolt_2','cellvolt_3','cellvolt_4','cellvolt_5','cellvolt_6','cellvolt_7','cellvolt_8','cellvolt_9']] df_chrgr_cellvolt_change = np.array(df_chrgr_cellvolt)#转数组 df_chrgr_cellvolt_sort = np.argsort(df_chrgr_cellvolt_change)#取排序号 df_sort_change = pd.DataFrame(df_chrgr_cellvolt_sort) df_sort_set = df_sort_change.apply(pd.value_counts)#计算各列出现排列序号的次数 df_sort_set.fillna(0, inplace=True)#Na值填充0 X_col=np.size(df_chrgr_cellvolt,0) #计算 X 的列数 if X_col > 0: temp_list1 = np.max(df_sort_set,axis=0) temp_list = temp_list1 < X_col/2 if any(temp_list):#序号变化的电芯 sn_choose1.append(sn) temp1 = pd.DataFrame(sn_choose1) return temp1#,temp2,temp3,temp4