Multi condition Pandas python

Viewed 27

I have a raw data frame like this:

ID test 1 test 2 test 3
A 5 3 8
B 3 7 9
A 7 3 4
A 1 8 0
B 6 3 7

I want to figure out whether ID A or B passed the test which would look like

ID test 1 test 2 test 3
A 5 (OK) 3 (Fail) 8 (Fail)
A 7 (Fail) 3 (OK) 4 (Fail)
A 1 (OK) 8 (OK) 0 (OK)
B 6 (OK) 3 (OK) 7 (Fail)
B 3 (Fail) 7 (OK) 9 (Fail)

As you can see ID A passed each test at least 1 time so its final judgement is "OK" but for ID B it never passed the test 3 so its final judgement would be fail.

Now using my lazy, inefficient brain, the logic of the code would be:

  1. check the duplicates on ID column and save the rows that shares same ID
  2. check the test results by columns (test 1 , test 2 and test 3) -> I am pretty sure how to write the codes for this part
  3. run through each test result and if each test was passed at least once then good to go, but if not highlight the ID

I am not simply asking any one of you to write a code for me, but instead I would really appreciate if someone could let me know any function that can be applied to this matter.

THANKS!

0 Answers
Related