Ruban
Ruban

Reputation: 123

how to impute a value in particular columns in a dataframe

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

Answers (1)

Adrien Wehrlé
Adrien Wehrlé

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

Related Questions