I have created a function like this.
def age_group(age):
if age >= 18 & age <= 25:
return '18-25'
elif age > 25 & age <= 40:
return '25-40'
elif age > 40 & age <= 55:
return '40-55 '
else:
return '55+'
age_group(20)
Then I have used the apply method like this survey['age_group']=survey['age'].apply(age_group)
But the age_group column returns '18-25' age group in all the columns even when the age is greater than 25 or less than 18