Home > Software design >  How to take the maximum value of a row if it has repeated values elsewhere in the column and return
How to take the maximum value of a row if it has repeated values elsewhere in the column and return

Time:08-30

I have created a matrix by concatenating two arrays as column vectors, so I have something like the following:

| ErrKappa | error |
| :--------|------:|
| 1        | 0.5   |
| 2        | 0.76  |
| 2        | 0.5   |
| 3        | 0.15  |
| 4        | 0.5   |
| 4        | 0.9   |
| 2        | 0.5   |
| 3        | 0.05  |

And then I need it to output another matrix that which just has the maximum error of the values which are the same from the matrix, so the new one will look like the following:

| ErrKappa | error |
| :--------|------:|
| 1        | 0.5   |
| 2        | 0.76  |
| 3        | 0.5   |
| 4        | 0.9   |

Please note that ErrKappa doesn't need to be put in order, it just so happened that it appeared like that in this toy example. Any help is massively appreciated. Thanks!

CodePudding user response:

Unfortunately I don't quite understand your problem:
do you want the program to return a matrix with the 4 largest values each different?

CodePudding user response:

EK = [1,2,2,3,4,4,2,3]
er = [0.5,0.76,0.5,0.15,0.5,0.9,0.5,0.5]
import pandas as pd
df = pd.DataFrame({'ErrorKappa':EK,'error':er})
df.groupby('ErrorKappa').max()
            error
ErrorKappa       
1            0.50
2            0.76
3            0.50
4            0.90
  • Related