首页 > 解决方案 > categories the age of year and month using python pandas

问题描述

I am trying to categories the age of some people to a new columns

but I am facing a problem in doing that

enter image description here

I want to say if the his/her age in month >> put 0

def age(Age):


if Age < 6  :
    return 0
elif Age <11 :
    return 1
elif Age <16 :
    return 2
elif Age <21 :
    return 3
elif Age <26 :
    return 4
elif Age <31 :
    return 5
elif Age <36 :
    return 6   
else:
    return 7


data['AGE_CD']=data['Age'].apply(age)

thank you.

标签: pythonpandas

解决方案


推荐阅读