jeudi 28 décembre 2017

Low speed of python using while ,for,if-else condition

Hi I have below code in python . I am comparing multiple columns to 1 single data each time based on certain flag value presence. Here two such sets are shown. ST9 and ST1 I am using while loop,for and if-else condition. But it is taking almost 13 minutes to process. How can I increase the computation speed.

i=0
Reslt_9=[]

while i<len(xx):
    for val in xx.ST9:
      if val==4:
         xz = xx[['SV1','SV2','SV3','SV4','SV5','SV6','SV7','SV8','SV9','SV10','SV11','SV12']].eq(xx['G9'], axis=0).assign(no = True)
         i1 = xz.values.argmax(axis=1)
         Reslt_9 =  np.append(Reslt_9,xx['R9'][i] -xx[['PR1','PR2','PR3','PR4','PR5','PR6','PR7','PR8','PR9','PR10','PR11','PR12']].assign(no = np.nan).values[xx.index, i1][i])
      elif val==2:
         Reslt_9=np.append(Reslt_9,0) 
      i=i+1

a2=0
Reslt_1=[]
aa=read_data
while a2<len(aa):
# Debug area
    for val1 in aa.ST1:
      if val1==4:
           a = aa[['SV1','SV2','SV3','SV4','SV5','SV6','SV7','SV8','SV9','SV10','SV11','SV12']].eq(aa['G1'], axis=0).assign(no = True)
           a1 = a.values.argmax(axis=1)
           Reslt_1 = np.append(Reslt_1,aa['R1'][a2] - aa[['PR1','PR2','PR3','PR4','PR5','PR6','PR7','PR8','PR9','PR10','PR11','PR12']].assign(no = np.nan).values[aa.index, a1][a2])
      elif val1==2:
           Reslt_1 = np.append(Reslt_1,0)
      a2=a2+1
   .....................

Aucun commentaire:

Enregistrer un commentaire