lundi 30 novembre 2020

Translate these multiple conditional from R to Python

I would appreciate if you could help me on this one, please.

The Problem

ifelse(df2$Status=="Completion", "Completed",
    ifelse(df2$Status=="Declined"|df2$Status=="DIP Declined","Declined",
        ifelse(df2$Status=="Withdrawn"& df2$Decision == "Decline" | df2$Decision == "Refer" | df2$Decision == "Decline"),"Declined - Withdrawn",
             ifelse(df2$Status=="Withdrawn","Withdrawn", "In-Flight"))))

My Attempt

np.where(df2["Status"]=="Completion", "Completed",\
    (np.where(np.logical_or(df2.Status=="Declined",df2.Status=="DIP Declined"),"Declined",\
        (np.where(np.logical_and(df2.Status=="Withdrawn",np.logical_or(np.logical_or(df2["Decision"]=="Decline",df2["Decision"]=="Refer"),df2["Decision"]=="Decline"),"Declined - Withdrawn",
            (np.where(df2.Status=="Withdrawn","Withdrawn","In-Flight")
 )))))))

Error message

TypeError: ufunc() takes from 2 to 3arguments but 4 were given

Thank you!

Aucun commentaire:

Enregistrer un commentaire