mardi 24 août 2021

If - Elif - Else / Condition [closed]

I am trying to create a loop based on certain values in the Country Column. The results should populate in the ResultG column. Basically, the code below would translate in if the country is the UK run this action. I am not sure what I am doing wrong. Any suggestion is more than welcomed. Thank you.

if df["Country"].any('1','2','12', axis=1):
    df['ResultG'] = df['OneCol'].apply(lambda x: ' '.join(list(set(x.split()) & set(words.words()))))
elif df["Country"].any('3', axis=1):
    df['ResultG'] = df['OneCol'].apply(lambda x: ' '.join(list(set(x.split()) & set(list_fr))))
elif df["Country"].any('4', axis=1):
    df['ResultG'] = df['OneCol'].apply(lambda x: ' '.join(list(set(x.split()) & set(list_de))))
elif df["Country"].any('5', axis=1):
    df['ResultG'] = df['OneCol'].apply(lambda x: ' '.join(list(set(x.split()) & set(list_it))))
elif df["Country"].any('6', axis=1):
    df['ResultG'] = df['OneCol'].apply(lambda x: ' '.join(list(set(x.split()) & set(list_es))))
elif df["Country"].any('10', axis=1):
    df['ResultG'] = df['OneCol'].apply(lambda x: ' '.join(list(set(x.split()) & set(list_se))))
else:
     df['ResultG'] ="blank result"

Aucun commentaire:

Enregistrer un commentaire