I am new to using python and I have tried to search for the answer on multiple websites but maybe because I am new I could not find what I am looking for. I am using pandas dataframe for this. My table looks something like this-
C1 | C2 | C3 | C4 |
---|---|---|---|
ABCD | 11 | A29 | 20 |
ABCD | -11 | A29 | -20 |
ABCD | 15 | A29 | 35 |
ABCD | 2 | A29 | 5 |
ABCD | 2 | A01 | 5 |
PQRS | 2 | A29 | 30 |
PQRS | 3 | A03 | 45 |
PQRS | -1 | A03 | -10 |
You can see, columns C1 and C3 can have repeated values. What I am trying to do is have adding the C2 and C4 columns but only if the (first condition) C1 column values match and then C2 values match (2nd condition). So the resulted columns will look like this
C1 | C2 | C3 | C4 |
---|---|---|---|
ABCD | 17 | A29 | 40 |
ABCD | 2 | A01 | 5 |
PQRS | 2 | A29 | 30 |
PQRS | 2 | A03 | 35 |
Appreciate any kind of help or even if you could forward me to the right page where I might find a solution. I am unable to put two conditions into my for loop and also how to eliminate the rows after they are being added to the previous one (if both the conditions are matched)
Thanks.