jeudi 19 décembre 2019

IF STATEMENTS CHARACTERS CONDITIONS

Trying to translate SAS code into Python. The idea is to add a value based on character condition. exemple : if I look for rows with auto like 'auto_mobile_lyon, I would like 'auto' as the new value

for i in df1['A_SEGMENT']: 
    if i in 'AUTO': 
        df1['SEGMENT']=df1['A_SEGMENT'].str[:18]
    elif i in 'PROMO':
        df1['SEGMENT']=df1['A_SEGMENT'].str[:24]
    else:
        df1['SEGMENT']=df1['A_SEGMENT'].str[:14]

issue : the loop does not stop...

Aucun commentaire:

Enregistrer un commentaire