0

If I have a dataframe containing data of a set of people, in which 'age' is one of the columns. Now I want to create another column in dataframe, which would tell if that person is a child or a middle aged person or senior citizen.

I know this can be implemented using the pd.cut() function. But I wanted to know if there is a way I can do it using a switch statement in lambda function inside df.apply(). It should be something like this:

if i between 0 and 10: Child
else if i between 10 and 30: Adult
else if i between 30 and 45: Middle aged
else if i between 45 and 60: Old
else if i > 60: Senior citizen 

EDIT: the duplicate does not answer my question because I would like a solution that does not use pd.cut().

joanis
  • 10,635
  • 14
  • 30
  • 40
Amruth Lakkavaram
  • 1,467
  • 1
  • 9
  • 12

0 Answers0