Not supported between str and int

Hello!
I am stuck while running my code below. I would really appreciate your help in detailing what the problem could be?
Thanks
Wole

Screen Link: https://app.dataquest.io/m/348/guided-project%3A-clean-and-analyze-employee-exit-surveys/11/next-steps

My Code: <def employee_retirement_age(age):
if age >= 50:
return ‘Old Age’
elif 40 <= age < 50:
return ‘Middle Age Adult’
elif 20 <= age < 40:
return ‘Young Adult’
elif pd.isnull(age):
return np.nan
else:
return ‘Young Adolescent’

combined_age_updated[‘Age_retirement_cat’] = combined_age_updated[‘age’].apply(employee_retirement_age)

Check the unique values after the updates

combined_age_updated[‘Age_retirement_cat’].value_counts()>

What I expected to happen: I expect my code to aggregate my data based on age column

What actually happened:

TypeError: '>=' not supported between instances of 'str' and 'int

<I tried runing my code but it shows the above error, What could be the problem?>

It seems age as string datatype instead of numeric.

Convert str age inti int data type

def employee_retirement_age(age):
    age = int(age)   # Convert string to intiger before comparing
    if age >= 50:
        return 'Old Age'
    elif 40 <= age < 50:
        return 'Middle Age Adult'
    elif 20 <= age < 40:
        return 'Young Adult'
    elif pd.isnull(age):
        return np.nan
    else:
        return 'Young Adolescent'

This should work.

Thanks, when I run my code, it still shows me some value error:

ValueError: cannot convert float NaN to integer

Is there anyway I can remove NaN from age column?
Thanks once again

Put this condition at first it will resolve error

like

def employee_retirement_age(age):
    age = int(age)   # Convert string to intiger before comparing
    if pd.isnull(age):
        return np.nan
    elif age >= 50:
        return 'Old Age'
    elif 40 <= age < 50:
        return 'Middle Age Adult'
    elif 20 <= age < 40:
        return 'Young Adult'
    else:
        return 'Young Adolescent'