I have the following dataframe:
+----+----+---------+----------+
| |A | B | C |
|----+----+---------+----------|
| 0 |S | nan | 5464.5 |
| 1 |A | 5464.5 | 5464.5 |
| 2 |A | 5675.5 | nan |
| 3 |S | 5670 | nan |
| 4 |A | 5664 | nan |
| 5 |B | 5635.5 | nan |
| 6 |D | 5624 | nan |
| 7 |C | 5624 | nan |
| 8 |X | nan | 5464.5 |
| 9 |C | 5715.5 | nan |
| 10 |D | 4704 | 5000 |
+----+----+---------+----------+
I want to replace the nan values in B and values in B < 5000 with a condition: if column A is 'S' it should be replaced with Column C if column A is 'X' it should be replaced with column C+10 if column A is 'D' it should be replaced with column C-10
so the result should look like this:
+----+----+---------+----------+
| |A | B | C |
|----+----+---------+----------|
| 0 |S | 5464.5 | 5464.5 |
| 1 |A | 5464.5 | 5464.5 |
| 2 |A | 5675.5 | nan |
| 3 |S | 5670 | nan |
| 4 |A | 5664 | nan |
| 5 |B | 5635.5 | nan |
| 6 |D | 5624 | nan |
| 7 |C | 5624 | nan |
| 8 |X | 5474.5 | 5464.5 |
| 9 |C | 5715.5 | nan |
| 10 |D | 4704 | 4990 |
+----+----+---------+----------+
What is the most elegant, simple and readable way to solve this. I tend to loop over the table and change it, but i can find a lot of warnings not to do this.