I am trying to transform the age columns of a pnada dataframe by applying apply function. how to make below code work or is there a more pythonic way way to do this.
cps=(cps.assign(Age_grp_T=cps['age'].apply(lambda x:{x>=71:'Tradionalists',
71>x>=52:'Baby Boomers',
52>x>=46:'Generation X',
46>x>=16:'Millennials'}.get(x, ' ')))
Aucun commentaire:
Enregistrer un commentaire