vendredi 30 mars 2018

Why my if elif logic in Python is not working.. Please explain

Dataframe(test1):

cons_flag

Mas

Mas

Wood

Wood

Wood

Mas

Conc

Wood

OUTPUT:

cons_flag new_var

Mas MASOM

Mas MASOM

Wood MASOM

Wood MASOM

Wood MASOM

Mas MASOM

Conc MASOM

Wood MASOM

CODE USED:

for x in test1['cons_flag']:
    if x.find('Mas'):
        test1['new_var']="MASOM"
    elif x.find('Wood'):
        test1['new_var']= "WOODEN"

Aucun commentaire:

Enregistrer un commentaire