Given a dataframe
{'id': {0: 100, 1: 100, 2: 101, 3: 101, 4: 102},
'A': {0: True, 1: False, 2: True, 3: False, 4: True},
'B': {0: False, 1: True, 2: False, 3: True, 4: False},
'C': {0: False, 1: False, 2: False, 3: False, 4: False}}
which looks like this
How do we merge rows so that there is only one row for each unique id, retaining all True values?
Goal:
Use groupby.max
:
df.groupby('id', as_index=False).max()