I have the following code that generates the two columns.
import pandas as pd
data = {'Group': ['1', '1', '1', '1', '1', '1',
'2', '2', '2', '2', '2', '2',
'3', '3', '3', '3', '3', '3',
'4', '4', '4', '4', '4', '4',],
'Test1': ['ABC', 'CDE', 'EFG', 'GHI', 'IJK', 'KLM',
'MNO', 'OPQ', 'QRS', 'STU', 'UVW', 'WXYZ',
'ABC', 'CDE', 'EFG', 'GHI', 'IJK', 'KLM',
'MNO', 'OPQ', 'QRS', 'STU', 'UVW', 'WXYZ',],
'Test2': ['1234','4567', '8910', '1112', '1314', '1415',
'1516', '1718', '1920', '2122', '2324', '2526',
'2728', '2930', '3132', '3334', '3536', '3738',
'2940', '4142', '4344', '4546', '4748', '4950'],
'Value': [True, True, False, False, False, True,
True, True, True, True, True, True,
True, True, True, True, True, False,
True, True, True, False, True, True,],
}
df = pd.DataFrame(data)
print(df)
So, by checking the last 2, 3, or 4 rows in each group if they return False, I want to return False. And if all the values are True then, I want to return true for all rows. From the above code, the expected outcome is this. If we check for the last 3 rows in each group
Group | Value
----- | -----
1 | False
1 | False
1 | False
2 | True
2 | True
2 | True
3 | False
3 | False
3 | False
4 | False
4 | False
4 | False