I am trying to perform a specific operation on a data frame. Given the following data block:
df1 = pd.DataFrame({
'id': [0, 1, 2, 1, 3, 0],
'letter': ['a','b','c','b','b','a'],
'status':[0,1,0,0,0,1]})
id letter status
0 a 0
1 b 1
2 c 0
1 b 0
3 b 0
0 a 1
I would like to create another data framework that contains rows from df1 based on the following restriction.
If two or more lines have the same identifier and letter, return any line with status 1. All other lines should be copied.
The resulting data file should look like this:
id letter status
0 a 1
1 b 1
2 c 0
3 b 0
Any help is appreciated. thank you
source
share