<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Printing the highest value between a range of values of a field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067336#M61329</link>
    <description>&lt;P&gt;I'm completly new with python and wanted to do this little project that would be very useful. What I want to do in the end is having a little window pop up and showing the highest value of a field but only for a specific range of values, like between 1000 and 2000. Here's an example:&lt;/P&gt;&lt;TABLE border="1" width="9.786817915118325%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%" height="25px"&gt;Field1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100%" height="25px"&gt;1003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2005&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100%" height="25px"&gt;3003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100%" height="25px"&gt;3008&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;What I need in the end is a list like this (but for now I'd be happy to just print out the right values):&lt;/P&gt;&lt;TABLE border="1" width="20%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%" height="26px"&gt;&lt;P&gt;Zone1 = 1003&lt;/P&gt;&lt;P&gt;Zone2 = 2005&lt;/P&gt;&lt;P&gt;Zone3 = 3008&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With advice and code from another place I managed to write this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;P&gt;import arcpy&lt;BR /&gt;fc = 'C:\..............\Einzelpunkt.shp'&lt;BR /&gt;fields = ['Identifika']&lt;BR /&gt;#setting up the max value variables&lt;BR /&gt;Zone1=0&lt;BR /&gt;Zone2=0&lt;/P&gt;&lt;P&gt;# For each row in the attribute table, use if statements&lt;BR /&gt;# to determine which category it is in and if it is bigger&lt;BR /&gt;# than the current max value for that category, update the&lt;BR /&gt;# max value variable&lt;BR /&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;if row[0]&amp;lt;20000 and row[0]&amp;gt;Zone1:&lt;BR /&gt;Zone1=row[0]&lt;BR /&gt;elif row[0]&amp;lt;30000 and row[0]&amp;gt;Zone2:&lt;BR /&gt;Zone2=row[0]&lt;/P&gt;&lt;P&gt;#keep adding elif statements to cover the rest of the Zones&lt;BR /&gt;#this will print out the last number used in the piano category&lt;BR /&gt;print "Zone1="+str(Zone1)&lt;BR /&gt;print "Zone2="+str(Zone2)&lt;BR /&gt;break&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From what I can understand the if statements only take into account the first value in the column, wich in the example shape I have is ~31000 wich makes the statements false and not change the variables.&lt;/P&gt;&lt;P&gt;How should I approach this?&lt;/P&gt;&lt;P&gt;Keep in mind I'm a complete beginner &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Jun 2021 14:00:50 GMT</pubDate>
    <dc:creator>Poncio</dc:creator>
    <dc:date>2021-06-11T14:00:50Z</dc:date>
    <item>
      <title>Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067336#M61329</link>
      <description>&lt;P&gt;I'm completly new with python and wanted to do this little project that would be very useful. What I want to do in the end is having a little window pop up and showing the highest value of a field but only for a specific range of values, like between 1000 and 2000. Here's an example:&lt;/P&gt;&lt;TABLE border="1" width="9.786817915118325%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%" height="25px"&gt;Field1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100%" height="25px"&gt;1003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2005&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100%" height="25px"&gt;3003&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100%" height="25px"&gt;3008&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;What I need in the end is a list like this (but for now I'd be happy to just print out the right values):&lt;/P&gt;&lt;TABLE border="1" width="20%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%" height="26px"&gt;&lt;P&gt;Zone1 = 1003&lt;/P&gt;&lt;P&gt;Zone2 = 2005&lt;/P&gt;&lt;P&gt;Zone3 = 3008&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With advice and code from another place I managed to write this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;P&gt;import arcpy&lt;BR /&gt;fc = 'C:\..............\Einzelpunkt.shp'&lt;BR /&gt;fields = ['Identifika']&lt;BR /&gt;#setting up the max value variables&lt;BR /&gt;Zone1=0&lt;BR /&gt;Zone2=0&lt;/P&gt;&lt;P&gt;# For each row in the attribute table, use if statements&lt;BR /&gt;# to determine which category it is in and if it is bigger&lt;BR /&gt;# than the current max value for that category, update the&lt;BR /&gt;# max value variable&lt;BR /&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;if row[0]&amp;lt;20000 and row[0]&amp;gt;Zone1:&lt;BR /&gt;Zone1=row[0]&lt;BR /&gt;elif row[0]&amp;lt;30000 and row[0]&amp;gt;Zone2:&lt;BR /&gt;Zone2=row[0]&lt;/P&gt;&lt;P&gt;#keep adding elif statements to cover the rest of the Zones&lt;BR /&gt;#this will print out the last number used in the piano category&lt;BR /&gt;print "Zone1="+str(Zone1)&lt;BR /&gt;print "Zone2="+str(Zone2)&lt;BR /&gt;break&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From what I can understand the if statements only take into account the first value in the column, wich in the example shape I have is ~31000 wich makes the statements false and not change the variables.&lt;/P&gt;&lt;P&gt;How should I approach this?&lt;/P&gt;&lt;P&gt;Keep in mind I'm a complete beginner &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 14:00:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067336#M61329</guid>
      <dc:creator>Poncio</dc:creator>
      <dc:date>2021-06-11T14:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067346#M61331</link>
      <description>&lt;P&gt;I've only glanced at this but I guess you just need an extra bit of logic so that the values less than 3000 etc. don't then override those of Zone 1.&lt;/P&gt;&lt;P&gt;I'd say just add something like below to make sure only values in 0-2000 are evaluated, then 2000-3000 etc.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:
  for row in cursor:
    if row[0]&amp;lt;20000 and row[0]&amp;gt;Zone1:
      Zone1=row[0]
    elif row[0]&amp;lt;30000 and row[0]&amp;gt;=20000 and row[0]&amp;gt;Zone2:
      Zone2=row[0]&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 11 Jun 2021 14:26:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067346#M61331</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-06-11T14:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067362#M61333</link>
      <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/167692"&gt;@DavidPike&lt;/a&gt;&amp;nbsp;has the solution for the basic question you asked. However, seeing that you have a Zone3 option, are you able to definitively say you will always have exactly 3 "zones" of data? If it could be variable, you could write the values to a dictionary and then handle the results however you need.&lt;/P&gt;&lt;P&gt;This all assumes that your naming of the zones is related to the first digit of the field values. It also assumes the range of possible values is 10000 - 99999. If it goes past that, one of the zones will get overwritten with a different range. For example, Zone1 will get overwritten with the 100k values, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;recorded_zones = {}
with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        current_zone_value = row[0]
        # Get first digit of value to identify the zone.
        current_zone = str(current_zone_value)
        current_zone = int(current_zone[0])

        # Compare zone values and updated if current zone value is higher.
        # Defaults recorded_zone_value to 0 if not found.
        recorded_zone_value = zones.get(current_zone, 0)
        if recorded_zone_value &amp;gt; current_zone_value:
            recorded_zones[current_zone] = current_zone_value

# Do something with the zone values
for zone, value in recorded_zones.items():
    print("Zone{} = {}".format(zone, value))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 17:43:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067362#M61333</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-06-11T17:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067634#M61349</link>
      <description>&lt;P&gt;&lt;STRONG&gt;divmod&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp;oft forgotten&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;field1 = arcpy.da.TableToNumPyArray(...table to use..., ...field name...)
field1 = np.array([101, 102, 103, 202, 205, 301, 303, 308])  # input array
# --- classify, slice, group and solve
np.divmod(field1, 100)  # divisor is 100 in this case
q, r = np.divmod(field1, 100)  #  return the quotient and remainder
split_idx = np.nonzero(np.diff(q))[0]  #  return the indices where they differ
group_vals = np.array_split(r, split_idx+1)  # split the remainder into groups

#  ---- some results
q
array([1, 1, 1, 2, 2, 3, 3, 3], dtype=int32)  # quotient
r
array([1, 2, 3, 2, 5, 1, 3, 8], dtype=int32)  # remainder
split_idx
array([2, 4], dtype=int64)  # the indices for the group

group_vals  # the remainders in each group
[array([1, 2, 3], dtype=int32),
 array([2, 5], dtype=int32),
 array([1, 3, 8], dtype=int32)]

maxs = [g.max() for g in group_vals]  # get the max per group
maxs
[3, 5, 8]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Options abound, but divmod rarely gets show-cased.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jun 2021 02:55:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1067634#M61349</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-06-12T02:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1075792#M61575</link>
      <description>&lt;P&gt;Sorry for the late response didn't have time to continue this...&lt;/P&gt;&lt;P&gt;Anyway I tried adding the lines and only prints out 0 in every zone&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 10:10:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1075792#M61575</guid>
      <dc:creator>Poncio</dc:creator>
      <dc:date>2021-07-06T10:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1075793#M61576</link>
      <description>&lt;P&gt;Sorry for responding this late...&lt;/P&gt;&lt;P&gt;Yes it's a variable amount of zones depending on the county. Right now I'm testing with a single county that has 34 zones. I'll look into this more after making it work with the county I'm testing on.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 10:13:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1075793#M61576</guid>
      <dc:creator>Poncio</dc:creator>
      <dc:date>2021-07-06T10:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1075828#M61580</link>
      <description>&lt;P&gt;just looked, for some reason I wrote 20,000 and 30,000.&amp;nbsp; change these to 2000 and 3000 and it will work.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 13:22:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1075828#M61580</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-07-06T13:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1075863#M61581</link>
      <description>&lt;P&gt;How you are dividing up 34 zones? I mentioned in my post that if you are using the first digit, you'll only get nine zones before it starts repeating (1 through 9).&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 14:39:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1075863#M61581</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-07-06T14:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1076643#M61626</link>
      <description>&lt;P&gt;Still doesn't work (and it's right to put X0000 since it's a prefix and 4 digits, I simplified a bit the digits in the data of my example but kept the right digits in the code)... But I think I found why: it prints the original value of the variable (if I put in 5 instead of 0 it prints 5), wich means that the if statement is not properly changing the variable to the value of the field. I tried to change the first part and instead of "if row[0]&amp;lt;20000" write&amp;nbsp; "if row[0]&amp;gt;20000" and it works for the first zone (the elif don't seem to work even if I put &amp;gt;, I think it needs to be "if" and not "elif"). I think the problem is that the values in the field are not in order compared to the FID and the first number is in zone 31 (312070 to be precise and the second is 312069), this is because of how the data is gathered and I can't chage it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think how it is now, it doesn't check everything but only the first row of the field?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 08:56:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1076643#M61626</guid>
      <dc:creator>Poncio</dc:creator>
      <dc:date>2021-07-08T08:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1076648#M61628</link>
      <description>&lt;P&gt;Yes Zones are divided by the first or "first and second" digit only. for example zone 2 is 2XXXX while zone 20 is 20XXXX. This is one of the main reasons I wan to automatically get the last number for each zone, since arcmap also doesn't order them correctly. For now I use select by attribute SQL:" identifika LIKE '2____' "; then open the attribute table, order from last to first and look what the last used number is.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 09:38:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1076648#M61628</guid>
      <dc:creator>Poncio</dc:creator>
      <dc:date>2021-07-08T09:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1076740#M61630</link>
      <description>&lt;P&gt;So would a rule be that if the number is over 4 digits, the remainder is taken from the beginning of the number and used as the zone? So if the number was 2361867, the zone would be 236?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 14:25:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1076740#M61630</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-07-08T14:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Printing the highest value between a range of values of a field</title>
      <link>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1089148#M62088</link>
      <description>&lt;P&gt;Sorry, like last time, we got a lot of work and I kinda left this little project where it was and forgot about this...&lt;/P&gt;&lt;P&gt;In the meantime I found another solution tho: I use the modelbuilder to make what I was doing manually wich is to select by attribute for the zone and get the max value of the selected. After that I use a simple Python script to take the values and visualize them in a separate window. Now it's just a matter of cleaning up the modelbuilder (would need to make the number inside the select SQL a variable wich most likely requires to make it entirely in Python, I tried to convert the model but it's quite messy and definely out of my current competence). For now I'm happy since the result is usable.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Aug 2021 07:11:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/printing-the-highest-value-between-a-range-of/m-p/1089148#M62088</guid>
      <dc:creator>Poncio</dc:creator>
      <dc:date>2021-08-15T07:11:45Z</dc:date>
    </item>
  </channel>
</rss>

