<?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: Field calculation with python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21732#M1681</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes exactly&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 24 May 2015 19:52:21 GMT</pubDate>
    <dc:creator>KONPETROV</dc:creator>
    <dc:date>2015-05-24T19:52:21Z</dc:date>
    <item>
      <title>Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21725#M1674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, i am very new in Python and i need a help at a script i want to build. I want to take the first value from a specific column and put it in the column b, and after that to substact a value = 5 from each row. So as to have this:&lt;/P&gt;&lt;P&gt;a&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; b&lt;/P&gt;&lt;P&gt;50&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; 50&lt;/P&gt;&lt;P&gt;30&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; 45&lt;/P&gt;&lt;P&gt;60&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; 40&lt;/P&gt;&lt;P&gt;29&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; 35&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Any help at that? Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2015 16:59:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21725#M1674</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-22T16:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21726#M1675</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your OIDs are in order and consecutive (0,1,2,3,...), you could apply a field calculation like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;ColumnA - (OID*5)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The better, more complicated way, not relying on OIDs, would be to use an &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/UpdateCursor/018w00000014000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;UpdateCursor&lt;/A&gt; and a counter to update each row value. Inside the cursor, you would have something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;row[0] = row[1] - (counter * 5)
counter = counter + 1
cursor.updateRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:53:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21726#M1675</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-10T20:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21727#M1676</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;with update cursor with your example won't i get&lt;/P&gt;&lt;P&gt;50 - 0&lt;/P&gt;&lt;P&gt;30 - 5&lt;/P&gt;&lt;P&gt;60 - 10? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2015 17:15:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21727#M1676</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-22T17:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21728#M1677</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Saying you want the "first" value is very relative; it depends on how the table is sorted. Do you really just want whatever value is in the first row or do you want a max/min?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2015 17:36:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21728#M1677</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-05-22T17:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21729#M1678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh, you're right, yes, you would. Read too fast.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Blake is getting at, you would first have to either collect the first or max value (whichever you want) into a variable and then run through the cursor:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;row[&lt;/SPAN&gt;&lt;SPAN class="number" style="font-weight: inherit; font-style: inherit; color: green; font-size: 9pt !important; background-color: inherit;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;] = maxValue&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; - (counter * &lt;/SPAN&gt;&lt;SPAN class="number" style="font-weight: inherit; font-style: inherit; color: green; font-size: 9pt !important; background-color: inherit;"&gt;5&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;)&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;counter = counter + &lt;SPAN class="number" style="font-weight: inherit; font-style: inherit; color: green; font-size: 9pt !important; background-color: inherit;"&gt;1&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;cursor.updateRow(row) &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:53:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21729#M1678</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-10T20:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21730#M1679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To follow on what &lt;A href="https://community.esri.com/migrated-users/48550"&gt;Blake T&lt;/A&gt; says, most if not all DBMSes do not guarantee the ordering of results unless you use an ORDER BY clause.&amp;nbsp; Even if you are not using GROUP BY clauses, you should use ORDER BY if you are processing results based on some type of order.&amp;nbsp; Relying on an index to return a certain order without using ORDER BY is basically relying on chance, even if chance has worked most of the time in the past.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 May 2015 16:18:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21730#M1679</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-05-23T16:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21731#M1680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or i can do that. My question here is can i put 10 as a parameter that user will put? Because i tried it unsuccesfully until now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fields = ['FID', 'a', 'b']&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, fields) as cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (row[0] == 0):&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = row[1]&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; a= row[2]&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; elif (row[0] &amp;gt; 0):&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = a - 10&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = row[2]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 May 2015 14:14:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21731#M1680</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-24T14:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21732#M1681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes exactly&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 May 2015 19:52:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21732#M1681</guid>
      <dc:creator>KONPETROV</dc:creator>
      <dc:date>2015-05-24T19:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21733#M1682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;most if not all DBMSes do not guarantee the ordering of results unless you use an ORDER BY clause&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've seen this statement before and I don't doubt that, technically, it may be true. However, I've never seen an example demonstrating this, never witnessed an Update Cursor returning records out of order myself, and never been provided with any measure of how often this may occur.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have just created 1 million records in a shapefile (of course, this creates an autonumbered FID), numbered them separately with an Update Cursor counter ("order not guaranteed"), and calculated the difference to a new field. Repeated 10x. In all cases, every single row returned difference of zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure: perfect out of ten million seems good to me, and I do realize that "big data" wants to be perfect every time (I don't want to be a credit card company's billionth transaction that messes up), but for static data that you can check, I'd just trust an Update Cursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 May 2015 16:57:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21733#M1682</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-05-25T16:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculation with python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21734#M1683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looking at some relevant DBMS documentation:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Microsoft SQL Server&lt;UL&gt;&lt;LI&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/ms188385.aspx"&gt;&lt;SPAN style="color: #000080; text-decoration: underline;"&gt;ORDER BY Clause (Transact-SQL)&lt;/SPAN&gt;&lt;/A&gt;:&amp;nbsp; "The order in which rows are returned in a result set are not guaranteed unless an ORDER BY clause is specified."&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Microsoft Access&lt;UL&gt;&lt;LI&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/bb208913%28v=office.12%29.aspx"&gt;ORDER BY Clause (Microsoft Access SQL)&lt;/A&gt;: "ORDER BY is optional. However, if you want your data displayed in sorted order, then you must use ORDER BY."&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;PostgreSQL&lt;UL&gt;&lt;LI&gt;&lt;A href="http://www.postgresql.org/docs/9.4/static/sql-select.html"&gt;&lt;SPAN style="color: #000080; text-decoration: underline;"&gt;SELECT (PostgreSQL)&lt;/SPAN&gt;&lt;/A&gt;:&amp;nbsp; "If ORDER BY is not given, the rows are returned in whatever order the system finds fastest to produce."&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;IBM DB2&lt;UL&gt;&lt;LI&gt;&lt;A href="http://www-01.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/com.ibm.db2z11.doc.apsg/src/tpc/db2z_orderresultrows.dita"&gt;Formatting the result table (Programming for DB2)&lt;/A&gt;:&amp;nbsp; "To retrieve rows in a specific order, use the ORDER BY clause. Using ORDER BY is the only way to guarantee that your rows are ordered as you want them."&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know Oracle has similar statements too, but the Oracle online help was obtuse enough I couldn't find a reference right away.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is pretty clear the DBMSes themselves don't guarantee a result set order without using the ORDER BY clause.&amp;nbsp; That said, do the ArcPy cursors (original and data access) do some default ordering after getting the result set from the DBMS?&amp;nbsp; I have no idea because I have yet to find any ArcPy documentation that addresses the issue.&amp;nbsp; Given that DBMS vendors clearly state there is no guaranteed ordering without ORDER BY, and Esri doesn't say anything about whether they order the cursors after getting the result sets, I always use the ORDER BY clause if I need the data to be in a certain order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Complexity isn't just defined by the number of records.&amp;nbsp; If all one works with is file-based data, like shapefiles or file geodatabases, ordering of result sets might be predictable, but enterprise DBMSes allow for complex workflows along with plenty of data so I prefer being explicit rather than implicit when wanting a certain order. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 22:45:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculation-with-python/m-p/21734#M1683</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-05-26T22:45:23Z</dc:date>
    </item>
  </channel>
</rss>

