I have a Pandas Dataframe with this table:
| name | phase | value |
|---|---|---|
| BOB | 1 | .9 |
| BOB | 2 | .05 |
| BOB | 3 | .05 |
| JOHN | 2 | .45 |
| JOHN | 3 | .45 |
| JOHN | 4 | .05 |
| FRANK | 1 | .4 |
| FRANK | 3 | .6 |
I want to find which phase has the maximum value in column 'value' and if the maximum value is the same then show the first value or random value for phase with maximum value
Desired result table:
| name | phase | value |
|---|---|---|
| BOB | 1 | .9 |
| JOHN | 2 | .45 |
| FRANK | 3 | .6 |
my solution was this:
df.groupby(['name'])[['phase','value']].max()
but it was returing incorrect values.
EDIT: slightly changed the values to represent the problem more accurately