I have a dataframe with columns:
import pandas as pd
import numpy as np
df = pd.DataFrame({
'A': [False, True, False, False, False, False, True, True, False, True],
'B': [True, False, False, False, True, True, False, False, False, False ]
})
df
A B
0 False True
1 True False
2 False False
3 False False
4 False True
5 False True
6 True False
7 True False
8 False False
9 True False
How to identify and mark the first occurrence that has [True - False] after encountering a [False - False] value pair? Every row that satisfies this condition needs to be flagged in a new column.
In the example above, [3 False False] is followed by [6 True False] and also, [8 False False] is followed by [9 True False].
These are the only valid solutions in this example.