voltrangecopy.py 1.4 KB

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