# max value of a field as variable

Question asked by Zitterbacke on Jun 2, 2020
Latest reply on Jun 2, 2020 by Davepike101@hotmail.com

Hello,

With the following script I was able to determine the maximum values of a column [POINT_Z] for certain groups from [ID_1].

``    #creating a list ->"mast_value" with unique values of field [ID_1]    with arcpy.da.SearchCursor(inLAS[:-4] + '_POLE_POINTS.SHP','ID_1') as max_cursor:        for row in max_cursor:            mast_value = sorted({row[0] for row in max_cursor})    #iterate through the list to find highest value in field [pointz], but only in features which have the value of the element of the list "mast_value"    field = "ID_1"    for mast in mast_value:        abfrage = field + " = " + str(mast)        with arcpy.da.SearchCursor(inLAS[:-4] + '_POLE_POINTS.SHP',('POINT_Z', 'FID'), where_clause=abfrage) as mast_cursor:            mylist = []            for row1 in mast_cursor:                #print('ID ' + str(mast) + u': max altitude ' + str(max(mast_cursor)))                print(str(max(mast_cursor)))``

With the output I can display the results. A manual check showed that the result is correct.

``ID 1: max altitude (477.56, 5997) ID 7: max altitude (523.27, 3401) ID 16: max altitude (495.69, 3203) ID 38: max altitude (495.69, 5574) ID 39: max altitude (470.16, 5986) ID 44: max altitude (503.93, 4713) ID 63: max altitude (503.97, 4185) ID 73: max altitude (463.67, 4205) ID 75: max altitude (518.59, 2880) ID 77: max altitude (463.63, 5877) ID 79: max altitude (485.91, 5594) ID 87: max altitude (482.06, 853) ID 88: max altitude (475.2, 1836) ID 91: max altitude (492.0, 1074) ID 97: max altitude (468.77, 1323) ID 98: max altitude (462.52, 1546) ID 99: max altitude (463.81, 1294)``

To continue working (selection), I need the corrosponding value [FID] (second value in the brackets) of the maximum value of [POINT_Z] as a variable. My attempt to write the result into a variable

``myMastList = str(max(mast_cursor))``

fails with an error message.

``File "E:\Documents\LAS\Las_Wire.py", line 264, in masten myMastList = str(max(mast_cursor))ValueError: max() arg is an empty sequence ``

How can I write the value of [FID] (second value in the brackets in the output) from the highest value of [POINT_Z] (or both [FID] and [POINT_Z]) into a variable?