I want to replace all the 'male' in the 'Sex' column to 1 and all the 'female' to 0.
Here is my dataframe df:
Pclass Sex Age SibSp Parch
0 3 male 22.0 1 0
1 1 female 38.0 1 0
2 3 female 26.0 0 0
3 1 female 35.0 1 0
4 3 male 35.0 0 0
5 3 male 2.0 3 1
6 3 female 27.0 0 2
7 2 female 14.0 1 0
8 3 female 4.0 1 1
9 1 female 58.0 0 0
I used the pd.get_dummies
:
pd.get_dummies(df.Sex)
But it creates two columns male and female like this:
female male
0 0 1
1 1 0
2 1 0
3 1 0
4 0 1
On the Other hand I want only a single column of sex denoting 1 for male and 0 for female.
I know that i can use a for loop to iterate over all the rows and change but is there a pandorable way to do this??