Reputation: 123
i have a column called gender in which there is few misspelled word and 'f' . I tried imputing in the below way but it imputed all the columns.
df[df['Gender'] == 'F' ] = 'abc'
output:
EmployeeID Attrition Age TravelProfile Department HomeToWork EducationField Gender HourlnWeek Involvement ... JobSatisfaction ESOPs NumCompaniesWorked OverTime SalaryHikelastYear WorkExperience LastPromotion CurrentProfile MaritalStatus MonthlyIncome
0 abc abc abc abc abc abc abc abc abc abc ... abc abc abc abc abc abc abc abc abc abc
19 abc abc abc abc abc abc abc abc abc abc ... abc abc
how to overcome this? and impute only gender column
Upvotes: 0
Views: 390
Reputation: 191
df.loc[df['Gender'] == 'F', 'Gender' ] = 'abc'
should work! You have to index with loc
and specify the row and column!
Upvotes: 1