I have a data frame as seen:
How to check conditions when results change from ‘NO’ to ‘OK’ and if it does populate the next column as true. Results should look like this:
>Solution :
My understanding question is need test OK if duplicated group only, so here are solutions with more data:
#test OK
m = df['Result'].eq('OK')
#first values per groups by consecutive values
m1 = m.ne(m.shift())
#chained consecutive OK with first values per groups
df['check1'] = m1.cumsum().duplicated(keep=False) & m1
#chained OK if from NO to OK with consecutive OK
df['check2'] = (m & df['Result'].shift().eq('NO')) & m1.cumsum().duplicated(keep=False)
print (df)
Result check1 check2
0 OK False False
1 NO False False
2 OK True True
3 OK False False
4 NO False False
5 OK True True
6 OK False False
7 OK False False
8 NO False False
9 OK False False
10 NO False False
11 OK False False

