Reputation: 11
Let's say that I have a data frame with a list of names and their gender. The default data frame has either a "0" or a "1" in the gender column for each name of the person in which the "0" implies that the person is a male while the "1" implies that the person is a female. How do I change the zeros and the ones in the gender column to males and females?
Upvotes: 1
Views: 423
Reputation: 114300
Direct indexing:
df['gender'] = np.array(['male', 'female'])[df.gender]
Upvotes: 0
Reputation: 2947
Just do:
df['gender'] = df['gender'].map({1:'female', 0:'male'})
OR
df.loc[(df.gender == 0), 'gender'] = 'male'
df.loc[(df.gender == 1), 'gender'] = 'female'
Upvotes: 1