How to use pd.cut in pandas

前端 未结 1 1252
自闭症患者
自闭症患者 2021-01-15 08:29

Can anyone help me figure out why this isn\'t working:

ages = [\'15-19\',\'20-24\',\'25-29\',\'30-34\',\'35-39\',\'40-44\',\'45-49\',\'50-54\',\'55-59\',\'60         


        
相关标签:
1条回答
  • 2021-01-15 09:19

    Your "range" is not correct, try:

    ages = ['15-19','20-24','25-29','30-34','35-39','40-44','45-49','50-54','55-59','60-64','65-69','70-74','75-79','80-84']
    race['age_group'] = pd.cut(race.Age,range(15,86,5),right=False, labels=ages)
    race[['Age','age_group']].head(15)
    
    0 讨论(0)
提交回复
热议问题