Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading