Male_Female = users[['occupation','gender','age']]
Male_Female
Output
occupation gender age
0 technician M 24
1 other F 53
2 writer M 23
3 technician M 24
4 other F 33
I need to convert the string from M=1, F=0
Male_Female_numeric = Male_Female(np.where((users['gender'] == 'M'), 1, 0))
Male_Female_numeric
I got error
TypeError: 'DataFrame' object is not callable
Disclaimer: I got the output with the below code
def gender_to_numeric(x):
if x == 'M':
return 1
if x == 'F':
return 0
users['gender_n'] = users['gender'].apply(gender_to_numeric)
How to achieve the same output using np.where