Use:
df = pd.DataFrame({'test': [1,50,51,20,0,2**11]})
def check(val):
if val == 50:
return '50'
else:
return '7'
df['test'].apply(lambda x: check(x))
Output:
0 7
1 50
2 7
3 7
4 7
5 7
Name: test, dtype: int64
Maybe your problem is with your data type:
df = pd.DataFrame({'test': [1,50,51,20,0,2**11]})
def check(val):
if val == 50:
return 50
else:
return 7
df['test'].astype(str).apply(lambda x: check(x))
In this case the output is:
0 7
1 7
2 7
3 7
4 7
5 7
Name: test, dtype: int64
More simply, use:
df.where(df==50, 7).astype(str)
again, note to the type of your data.