So I'm new to coding and working my way through the Titanic data set from Kaggle. In the data frame there are columns labeled "Age" and "Sex." I want to make a new column that has 4 values that indicate for different things: 0: Male aged 16 or over 1: Female aged 16 or over 2: Male aged 15 or younger 3: Female aged 15 or younger
So far I've gotten this, but this just splits it up into 3 values, not the 4 I'm looking for.
def person_detail(Person):
Age, Sex = Person
return 2 if Age < 16 else Sex
I then apply the function to the "Age" and "Sex" columns to get a new column. I know that you can't have two returns, but if it gets across what I am trying to accomplish, it would look something like the below.
def person_detail(Person):
Age, Sex = Person
return 2 if Age < 16 and Sex == 0
return 3 if Age < 16 and Sex == 1 else Sex
Thanks in advance. For reference in the "Sex" column 0 is for male, and 1 is for female.