Replacing negative numbers to zero is straightforward, see How to replace negative numbers in Pandas Data Frame by zero but I want to know how to do the opposite.
I want to replace the 0 here to -1:
But df.replace(0,-1)
or df[df == 0] = -1
gives me
It seems like I am able to replace the zeros into positive integers but I cannot replace them with negative integers (i.e. df.replace(0,-3)
replaces all my zeros with -253).
Am I missing something here?