vendredi 19 juillet 2019

Mistake in function Definition

I've written a fuction with lots of ELIF and OR statements. Code is working, but result is not what i'm expacting to get - absolutly the same values in DF table i'm cooperating with.

What am I doing wrong?

def some_func(x): if x == "aaaa" or "bbb" or "ccc" or "zzz": return 1 elif x == "ddd" or "eee" or "fff" or "ggg": return 2 elif x == "hhh" or "ppp" or "nnn" or "mmm": return 3 else: return 0

df.TABLE_name = df.TABLE_name.apply(some_func).astype('int64')

df['TABLE_name'].value_counts()

Out: 1 38133

According to function some result splited between 1, 2, 3

Aucun commentaire:

Enregistrer un commentaire