I have a DataFrame like this:
A B
0 name1_X 2
1 name2_X 2
2 name3_X 2
3 name1_Y NaN
4 name2_Y NaN
5 name3_Y NaN
where column A is the name
with a suffix _X
or _Y
, and column B is a value.
I want to make rows with _Y
equal to
`-1 * corresponding `_X`
with the same name.
The output should be,
A B
0 name1_X 2
1 name2_X 2
2 name3_X 2
3 name1_Y -2
4 name2_Y -2
5 name3_Y -2
Sometimes, the DataFrame will be
A B
0 name1_X 2
1 name1_Y NaN
2 name2_Y NaN
3 name3_Y NaN
and the output should be:
A B
0 name1_X 2
1 name1_Y -2
2 name2_Y NaN
3 name3_Y NaN
Non-overlapping part remains NaN
How can I solve this problem in a simple way?