TransWikia.com

Exchange each 100 in a dataframe for another value

Stack Overflow Asked by Tarik Benrabah on November 20, 2021

I have a csv file without headers and several values. I only want to exchange each 100 in the file for a 20.

I don’t know if it would work with an if condition. I know i can select each 100 with the following code

df[df,iloc[:,:== 100] but i don’t know how to only exchange each 100 for another value

One Answer

Assuming df is your dataframe, and 100 is the value you want to replace with 20. I would do:

df = df.replace(to_replace=100, value=20)

As shown in the guide

Answered by Williams Rizzi on November 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP