I have some dataset about genders of various individuals. Say, the dataset looks like this:
Male
Female
Male and Female
Male
Male
Female
Trans
Unknown
Male and Female
Some identify themselves as Male, some female and some identify themselves as both male and female.
Now, what I want to do is create a new column in Pandas which maps
Males to 1,
Females to 2,
Others to 3
I wrote some code
def gender(x):
if x.str.contains("Male")
return 1
elif x.str.contains("Female")
return 2
elif return 3
df["Gender Values"] = df["Gender"].apply(gender)
But I was getting errors that function doesn't contain any attribute contains. I tried removing str:
x.contains("Male")
and I was getting same error
Is there a better way to do this?