In my dataframe I have:
Name Sex Height
Jackie F Small
John M Tall
I have made the following function to apply to create a new column based off combinations:
def genderfunc(x,y):
if x =='Tall' & y=='M':
return 'T Male'
elif x =='Medium' & y=='M':
return 'Male'
elif x =='Small' & y=='M':
return 'Male'
elif x =='Tall' & y=='F':
return 'T Female'
elif x =='Medium' & y=='F':
return 'Female'
elif x =='Small' & y=='F':
return 'Female'
else:
return y
My line of code to apply this function:
df['GenderDetails'] = df.apply(genderfunc(df['Height'],df['Sex']))
and i get the following:
TypeError: Cannot perform 'rand_' with a dtyped [object] array and scalar of type [bool]
Any ideas on what im doing wrong here? this is my first go at using a function.
Thanks!