I have a dataframe df like this:
ID_USER CODE
0 433805 11.0
24 5448 44.0
48 3434 11.0
72 34434 11.0
96 3202 33.0
120 23766 33.0
153 39457 44.0
168 4113 33.0
172 3435 13.0
374 34093 11.0
And I try to replace the values from the 'CODE' column with other values.
11.0 and 44.0 -> 1 33.0 -> 0 all other -> 5
So I did among others the following:
df['CODE'] = df.apply(lambda s:func1(s))
def func1(x):
if (x['CODE'] == 11.0) or (x['CODE'] == 44.0):
return 1
elif (x['CODE'] == 33.0):
return 0
else:
return 5
And I get this error:
KeyError: ('NTL', u'occurred at index ID_UC')
How can I solve my problem?