How do you apply a groupby in a dataframe only when a condition is met in a row and still keep all other rows that do not meet said condition?
For instance, let's say I have a dataframe:
| Number | Version | Binary | Random column |
|---|---|---|---|
| 1 | 0 | True | a |
| 1 | 1 | True | b |
| 1 | 2 | True | c |
| 2 | 0 | False | a |
| 2 | 1 | False | b |
And, with this dataframe, I would like to groupby all of the numbers which binary value is True and keep only the one with the latest version (that is, the largest number), while still respecting and keeping the rows which do not meet the condition described.
That said, it should give a result like this:
| Number | Version | Binary | Random column |
|---|---|---|---|
| 1 | 2 | True | c |
| 2 | 0 | False | a |
| 2 | 1 | False | b |