Challenge questions-error show

I think my code is correct, but I dont know why there is still an error showing. I changed age column to float date type already. I dont know it does not work. Thank you in advance!!!

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

My Code:

def age_stage(col):
    if 30 > col >= 20:
        return '30~20'
    elif 60 > col >= 50:
        return '50~60'
    elif 50 > col >= 40:
        return '40~50'
    elif 40 > col >= 30:
        return '40~30'
    elif pd.isnull(col):
        return np.nan
    else:
        return 'over 60'
    
dis_true['age_stage']=dis_true['age'].apply(age_stage)

What actually happened:

TypeError: unorderable types: int() > str()

Can you share the code used to convert the column to float?

well, if you

changed age column to float date type

and python says :

TypeError: unorderable types: int() > str()

then there is definitely some error in your type conversion, to check this, simply try :

dis_true[‘age’].dtypes

and report back…

Hi @otavios.s

Please see my code changing the data type.

dis_true['age']=dis_true['age'].astype(str).str.replace('  ','/').str.replace(' ','/').str.replace('/','-').str.split('-').str[0]
dis_true['age'].astype(float)
dis_true['age'].value_counts().sort_values()```

I see the problem, i change the data type but i did not assign back to the variable. thank you for you reply!!

Good job! Also, you don’t need to use .astype(str) in the line below because the column already contains strings.

dis_true['age']=dis_true['age'].astype(str).str.replace('  ','/').str.replace(' ','/').str.replace('/','-').str.split('-').str[0]
1 Like