Replacing a particular integer by another integer in pandas dataframe

I have a data-set consisting of a column consisting of years (from 1996 to 2010), after exploration I have found that there are many observations having values equal to 0, which is an outlier. I want to replace the 0’s with 2010 and I have used the following code :


Above code is not replacing the 0’s with 2010. Please help !!
Thanks in advance

Try this code :


As for the code you are using, the problem is that is every time it is creating a new data frame and not modifying your actual data frame. Go through this link, I am sure this will help you.

1 Like

Hi @ravi_6767:

There is a simple syntax in pandas for this task:



1 Like

TypeError Traceback (most recent call last)
----> 1 df[‘flag’]=df[‘flag’].int().replace([-0.423666,2.341313],[0,1])

TypeError: ‘int’ object is not subscriptable

Looks like you are trying to update multiple values like on 0 some value and on 1 some value.
Is that correct ?
If is it so, then you must use map function and within that you can pass the values and items in dictionary.


Simple!!, try this
features.features.construction_year = features.features.construction_year.replace(0,2010)