mercredi 27 février 2019

Defining a function with condition

I have a silly problem. My df looks like this:

       FID_2     STA_SID           s2            s1  Qh_STA  Qh_FID2  \
14 222143.00 26040713.00           0.00        0.00    8.00    17.00   
15 222143.00 26040713.00           0.00        8.00    6.00    17.00   
13 222143.00 26040713.00           0.00        6.00    3.00    17.00   
17       NaN 26033594.00 29445425.00        1707.00    5.00      nan   

I defined the following function and command:

A = 0.8

def seekDO(row):
       if (row['Qh_STA'])/row['Qh_FID2'] < A :
          return 1
       if ((row['Qh_STA'] + row['s1'])/row['Qh_FID2'] < A) :
          return 1
       if ((row['Qh_STA'] + row['s1'] + row['s2']) / row['Qh_FID2'] < A) :
          return 1
       return 0

df['DO'] = df.apply (lambda row: seekDO(row),axis=1)

The problem is that for DO I get

    DO   
14  1  
15  1  
13  1  
17  0 

Instead of

    DO   
14  1  
15  0  
13  0  
17  0 

Can you perhaps see where I got mistaken?

Aucun commentaire:

Enregistrer un commentaire