Please read before pointing me to this thread: Python Pandas replace values by their opposite sign
I have the following DataFrame:
A | B
"1.9" | "S"
"1.2" | "H"
"1.9" | "S"
I want to replace values in column A to the values with opposite sign for all rows where B is "S", so the outcome is as follows:
A | B
"-1.9" | "S"
"1.2" | "H"
"-1.9" | "S"
Unfortunately all values are String.
I don't have a problem with setting the right query and update matching values with something else:
data.loc[(data["B"]) == 'S', data.columns[1]] = 999
This will result with the following:
A | B
"999" | "S"
"1.2" | "H"
"999" | "S"
So I know how to the the right entries for updates, but I have no idea how to update the values with their opposite sign.