<?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 Re: Iterate and Add Values from many fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428844#M33703</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/4872"&gt;JAKE RODEL&lt;/A&gt;​ done... &lt;A href="https://community.esri.com/migration-blogpost/55605"&gt;Working with blocks of data...&lt;/A&gt; &lt;/P&gt;&lt;P&gt;If you would prefer to use rolling data, rather than data blocked by year, then that example can be explained.&amp;nbsp; I used a 360 day year and 30 day month in the examples.&lt;/P&gt;&lt;P&gt;Rolling data, in case anyone is interested, takes a time series in sequential order from a start data and runs it as a big long sequence, not broken up by year or month.&amp;nbsp; You can 'block' the data into chunks of 7, 30, 365 increments sort of representing weekly, monthly and annual values.&amp;nbsp; You could make your life more difficult and contribute little to the statistical outcome, by using the actual number of days in a month (ie 28/29, 30 or 31) and the actual days in a year (365, 366... not going to go to 365.25 place)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 05 Mar 2016 15:56:29 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-03-05T15:56:29Z</dc:date>
    <item>
      <title>Iterate and Add Values from many fields</title>
      <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428837#M33696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can somebody please help me, I have been struggling with this part of my script for hours now. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to list the precip fields from my point feature class: &lt;/P&gt;&lt;P&gt;Create empty MaxValue list &lt;/P&gt;&lt;P&gt;For every record in my attribute table:&lt;/P&gt;&lt;P&gt;Add up(SUM) values from first 6 fields [0]-[5] and append value to list (by record line) &lt;/P&gt;&lt;P&gt;Add up(SUM) values from next group of 6 fields [1]-[6] and append value to list&lt;/P&gt;&lt;P&gt;Add up(SUM) values from next group of 6 fields [2]-[7] and append value to list &lt;/P&gt;&lt;P&gt;Loop to end of field list making sure it does not error at the end if it is not a full group of 6 records&lt;/P&gt;&lt;P&gt;After I have a MaxValue list it finds the MAX from that list and adds that to the MaxPrecip field. (I think I can get this part its just incrementally iterating over and summing groups of fields by record that is killing me)&lt;/P&gt;&lt;P&gt;Repeat for every point, there may be thousands of points and 20 or 120 fields.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri',sans-serif;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; PrecipFields = [f.name for f in arcpy.ListFields("asciiPoints","*")]&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; with arcpy.da.UpdateCursor("asciiPoints",PrecipFields) as cursor:&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MaxValue = []&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = 0&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(len(PrecipFields)):&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v = row&lt;I&gt; + row[i+1] + row[i+2] + row[i+3] + row[i+4] + row[i+5]&lt;/I&gt;&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Val.append(v)&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i+1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I even close?&amp;nbsp; &lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 14:43:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428837#M33696</guid>
      <dc:creator>JAKERODEL</dc:creator>
      <dc:date>2016-03-04T14:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate and Add Values from many fields</title>
      <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428838#M33697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jake,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It may help to see a sample of the attribute table.&amp;nbsp; Are you able to upload one?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 17:23:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428838#M33697</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2016-03-04T17:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate and Add Values from many fields</title>
      <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428839#M33698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG alt="Capture.JPG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/188807_Capture.JPG" style="width: 620px; height: 95px;" /&gt;&lt;/P&gt;&lt;P&gt;Hope this is legible.&amp;nbsp; Each field represents 1 hours worth of precipitation for a particular storm for a particular grid cell.&amp;nbsp; This example has only 2 records for simplicity, the actual database will have thousands.&amp;nbsp; What I want to do is find the consecutive 6 hour period that had the largest total precipitation for every record and input that value to the Max_Precip field.&amp;nbsp; So it would take fields [0] - [5],[1]-[6], [2]-[7],,ect and sum the total for each of those durations and and put them in a list.&amp;nbsp; Then before it moves to the next record it would find the max precipitation amount for whatever duration had the most precipitation from the list and update the Max_Precip field.&amp;nbsp; Then clear the list and do the same for the next record.&amp;nbsp; Unless there is an easier way.&amp;nbsp;&amp;nbsp; Hope that makes sense....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 17:48:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428839#M33698</guid>
      <dc:creator>JAKERODEL</dc:creator>
      <dc:date>2016-03-04T17:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate and Add Values from many fields</title>
      <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428840#M33699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;PrecipFields = [f.name for f in arcpy.ListFields(table,"Precip*")]

with arcpy.da.SearchCursor(table, PrecipFields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; maxValue = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j = 5
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; precipSum = [] 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while j &amp;lt; len(PrecipFields):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v = row&lt;I&gt; + row[i + 1] + row[i+2] + row[i+3] + row[i+4] + row&lt;J&gt;&lt;/J&gt;&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; precipSum.append(v)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maxValue.append(sorted(precipSum)[-1])


del cursor

i = 0

with arcpy.da.UpdateCursor(table, ["Max_Precip"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = maxValue&lt;I&gt;&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
del cursor&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:17:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428840#M33699</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T19:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate and Add Values from many fields</title>
      <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428841#M33700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jake&lt;/P&gt;&lt;P&gt;Interesting problem, sorry I didn't get to it, but I have two examples, one pertinent which I would like you to confirm.&lt;/P&gt;&lt;P&gt;The first example is to determine the maximum value found in 1x4 blocks for every 1x4 block in a row, then get a row max.&lt;/P&gt;&lt;P&gt;The second example, is to determine the sum in the 1x4 blocks for every 1x4 block in the row, then get the maximum sum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used integers, 20 per row and only 5 row, but the problem can easily be extended to many columns and rows and for any number of block sizes accounting for rows that aren't divisable by the block (ie 20 values in a row with a 1x3 block leaves 2 values left over which can be accounted for or dumped)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So here is the data, and I would appreciate any comments on whether this is the question(s) and the result you are looking for.&amp;nbsp; I will provide more details later.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;:---- Example 1 ----
1.&amp;nbsp; Input data.... subdivide the data into 1x4 blocks
[[&amp;nbsp; 1&amp;nbsp; 2&amp;nbsp; 3&amp;nbsp; 4&amp;nbsp; 5&amp;nbsp; 6&amp;nbsp; 7&amp;nbsp; 8&amp;nbsp; 9&amp;nbsp; 10&amp;nbsp; 11&amp;nbsp; 12&amp;nbsp; 13&amp;nbsp; 14&amp;nbsp; 15&amp;nbsp; 16&amp;nbsp; 17&amp;nbsp; 18&amp;nbsp; 19&amp;nbsp; 20]
[ 21&amp;nbsp; 22&amp;nbsp; 23&amp;nbsp; 24&amp;nbsp; 25&amp;nbsp; 26&amp;nbsp; 27&amp;nbsp; 28&amp;nbsp; 29&amp;nbsp; 30&amp;nbsp; 31&amp;nbsp; 32&amp;nbsp; 33&amp;nbsp; 34&amp;nbsp; 35&amp;nbsp; 36&amp;nbsp; 37&amp;nbsp; 38&amp;nbsp; 39&amp;nbsp; 40]
[ 41&amp;nbsp; 42&amp;nbsp; 43&amp;nbsp; 44&amp;nbsp; 45&amp;nbsp; 46&amp;nbsp; 47&amp;nbsp; 48&amp;nbsp; 49&amp;nbsp; 50&amp;nbsp; 51&amp;nbsp; 52&amp;nbsp; 53&amp;nbsp; 54&amp;nbsp; 55&amp;nbsp; 56&amp;nbsp; 57&amp;nbsp; 58&amp;nbsp; 59&amp;nbsp; 60]
[ 61&amp;nbsp; 62&amp;nbsp; 63&amp;nbsp; 64&amp;nbsp; 65&amp;nbsp; 66&amp;nbsp; 67&amp;nbsp; 68&amp;nbsp; 69&amp;nbsp; 70&amp;nbsp; 71&amp;nbsp; 72&amp;nbsp; 73&amp;nbsp; 74&amp;nbsp; 75&amp;nbsp; 76&amp;nbsp; 77&amp;nbsp; 78&amp;nbsp; 79&amp;nbsp; 80]
[ 81&amp;nbsp; 82&amp;nbsp; 83&amp;nbsp; 84&amp;nbsp; 85&amp;nbsp; 86&amp;nbsp; 87&amp;nbsp; 88&amp;nbsp; 89&amp;nbsp; 90&amp;nbsp; 91&amp;nbsp; 92&amp;nbsp; 93&amp;nbsp; 94&amp;nbsp; 95&amp;nbsp; 96&amp;nbsp; 97&amp;nbsp; 98&amp;nbsp; 99 100]]


2.&amp;nbsp; Now imagine what that would look like if subdivided

3.&amp;nbsp; maximum of each 1x4 block in each row
[[&amp;nbsp; 4&amp;nbsp; 8&amp;nbsp; 12&amp;nbsp; 16&amp;nbsp; 20]
[ 24&amp;nbsp; 28&amp;nbsp; 32&amp;nbsp; 36&amp;nbsp; 40]
[ 44&amp;nbsp; 48&amp;nbsp; 52&amp;nbsp; 56&amp;nbsp; 60]
[ 64&amp;nbsp; 68&amp;nbsp; 72&amp;nbsp; 76&amp;nbsp; 80]
[ 84&amp;nbsp; 88&amp;nbsp; 92&amp;nbsp; 96 100]]

4.&amp;nbsp; maximum of (2) by row
[ 20&amp;nbsp; 40&amp;nbsp; 60&amp;nbsp; 80 100]

: ---- Example 2 ----
5.&amp;nbsp; Let's do the sum of each 1x4 block and determine the row max

6. sums of each 1x4 block in each row
[[ 10&amp;nbsp; 26&amp;nbsp; 42&amp;nbsp; 58&amp;nbsp; 74]
[ 90 106 122 138 154]
[170 186 202 218 234]
[250 266 282 298 314]
[330 346 362 378 394]]

7. maximum of (6) by row
[ 74 154 234 314 394]&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this makes sense, and I look forward to feedback.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:17:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428841#M33700</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T19:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate and Add Values from many fields</title>
      <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428842#M33701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan.&amp;nbsp; I knew you would have an interesting and creative way to attack this.&amp;nbsp; Yes, example number 2 is exactly what I am looking for.&amp;nbsp; And that's great because in my example I mentioned 6hr but I will also be doing this for 24 and 72 hour durations as well.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Mar 2016 12:05:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428842#M33701</guid>
      <dc:creator>JAKERODEL</dc:creator>
      <dc:date>2016-03-05T12:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate and Add Values from many fields</title>
      <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428843#M33702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I will be posting a blog sometime today and it also deals with the case of missing data (you just need to do use a masked array). You can determine other statistical parameters if you need them, but I suspect you are looking for max, total rainfall in an X period or something like that&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Mar 2016 13:43:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428843#M33702</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-05T13:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate and Add Values from many fields</title>
      <link>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428844#M33703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/4872"&gt;JAKE RODEL&lt;/A&gt;​ done... &lt;A href="https://community.esri.com/migration-blogpost/55605"&gt;Working with blocks of data...&lt;/A&gt; &lt;/P&gt;&lt;P&gt;If you would prefer to use rolling data, rather than data blocked by year, then that example can be explained.&amp;nbsp; I used a 360 day year and 30 day month in the examples.&lt;/P&gt;&lt;P&gt;Rolling data, in case anyone is interested, takes a time series in sequential order from a start data and runs it as a big long sequence, not broken up by year or month.&amp;nbsp; You can 'block' the data into chunks of 7, 30, 365 increments sort of representing weekly, monthly and annual values.&amp;nbsp; You could make your life more difficult and contribute little to the statistical outcome, by using the actual number of days in a month (ie 28/29, 30 or 31) and the actual days in a year (365, 366... not going to go to 365.25 place)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Mar 2016 15:56:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterate-and-add-values-from-many-fields/m-p/428844#M33703</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-05T15:56:29Z</dc:date>
    </item>
  </channel>
</rss>

