mercredi 31 août 2016

Double IIF Statement in Python

I have an SQL code that has a double IIF statement in it, that is, the if true part is another IIF statement and I m trying to recreate this in python using np.where

the SQL code is:

IIF ([STATE] Is Null, IIF ([COUNTRY] Is Null,'No Country',[COUNTRY]), [STATE])

I've tried this:

DF['NewCol'] = np.where(DF['STATE'].isnull(),(np.where(DF['COUNTRY'].isnull(),'No Country','DF['COUNTRY']'),DF['STATE']))

any help appreciated

Aucun commentaire:

Enregistrer un commentaire