How to populate a field by the field name having the maximum value across the rows?

683
4
07-08-2021 08:25 PM
badrinathkar
New Contributor III

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

IdX1X2X3X4MaxValue
1105151166 
262305625 
384222824 
493278936 
571333577 
656546839 
722567172 
881524941 
979293332 
1037207351 

 

 

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
BlakeTerhune
MVP Regular Contributor

Does it matter how ties are broken (if two or more fields have the same maximum value)?

badrinathkar
New Contributor III

No.

0 Kudos
DanPatterson
MVP Esteemed Contributor

max takes the first


... sort of retired...
0 Kudos