Skip to content
Advertisement

How to replace irrelevant data into mean values?

Let’s say I have 600,000 data points in column for age. In the data there are values 0 and -1, which is not relevant for age. How can I change both 0 and -1 values in my data to the column mean value using python?

The code so far:

JavaScript

Advertisement

Answer

You can find the mean separatly and then use the correct replace syntax to replace desired values:

JavaScript

PS: Please use Stack Overflow code formatting instead of posting the image in the future. Thanks.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement