I have the following dataframe
Index education marital-status occupation gender target
0 bachelors never-married adm-clerical male 0
1 bachelors spouse exec-managerial male 0
2 hs-grad divorced handlers-cleaners male 0
3 11th spouse handlers-cleaners male 0
4 bachelors spouse prof-specialty female 0
5 masters spouse exec-managerial female 0
6 other other other-service female 0
7 hs-grad spouse exec-managerial male 1
8 masters never-married prof-specialty female 1
9 bachelors spouse exec-managerial male 1
Can someone explain to me why the following doesn't work - I feel like it should from what I've read and what I've seen applied.
def new_features(education, gender, target):
if [((education == 'bachelors') & (gender == 'male') & (target == 1))]:
result = 'educated_male_convert'
elif [((education == 'bachelors') & (gender == 'female') & (target == 1))]:
result = 'educated_female_convert'
else:
result = 'educated_not_determined'
return result
df['new_col'] = df.apply(lambda row: new_features(row['education'], row['gender'], row['target']), axis=1)
It just returns: educated_male_convert
I followed numerous tutorials and read other threads and applied the same code to my own dataset - not sure what I'm missing.
Any help would be appreciated