How to fix "ValueError: Series.replace cannot use dict-like to_replace and non-None value "

Question:

I tried to use this following line of code to replace the retirees’ incorrect days values ​​with 9000, but I get the error in the title. This is the line:
df.replace(df.loc[(df['days_employed']>100000) & (df['income_type']=='retiree')], 9000)

Asked By: Riuk2252

||

Answers:

refer to the LOC documentation, section ‘setting values’

the second parameter to the loc is the column to update

# replace the col-to-update, with the column you like to update
df.loc[(df['days_employed']>100000) & (df['income_type']=='retiree'),'col-to-update']= 9000

Answered By: Naveed
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.