I have a point shapefile that contains five fields including the Id field. Now, I want to find the max value across the rows and populate another row with the field name having the maximum value. How to do this using python?
The table looks like this
Id | X1 | X2 | X3 | X4 | MaxValue |
1 | 105 | 15 | 11 | 66 | |
2 | 62 | 30 | 56 | 25 | |
3 | 84 | 22 | 28 | 24 | |
4 | 93 | 27 | 89 | 36 | |
5 | 71 | 33 | 35 | 77 | |
6 | 56 | 54 | 68 | 39 | |
7 | 22 | 56 | 71 | 72 | |
8 | 81 | 52 | 49 | 41 | |
9 | 79 | 29 | 33 | 32 | |
10 | 37 | 20 | 73 | 51 |
conceptually
vals = [105, 15, 111, 66]
["X1", "X2", "X3", "X4"][vals.index(max(vals))]
'X3'
in practice
vals = [105, 15, 111, 66]
["X1", "X2", "X3", "X4"][vals.index(max(!X1!, !X2!, !X3!, !X4!))]
without actually checking.... obviously a field calculation into a string/text field using python parser
Does it matter how ties are broken (if two or more fields have the same maximum value)?
No.
max takes the first