<?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: Calculating (with Python) a 2nd field based on a 1st field in 10.2 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541756#M42298</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Looking it over I noticed the work space was not set. I'm assuming the code here comes after the workspace is set right? Sorry, I'm a newbie to Python. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Jan 2014 10:37:32 GMT</pubDate>
    <dc:creator>JoelGuerra</dc:creator>
    <dc:date>2014-01-09T10:37:32Z</dc:date>
    <item>
      <title>Calculating (with Python) a 2nd field based on a 1st field in 10.2</title>
      <link>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541753#M42295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am attempting to write a script that takes one field and sorts it from largest to smallest. I then want to add another field next to the sorted field in order to indicate a sequential order of the first field (ranging from 1 to what ever is the last occurence is). In other words, calculate a numeric sequential order of a field and populate that field with numbers based and in conjunction with another field. Is it possible? Any tips ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jan 2014 17:46:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541753#M42295</guid>
      <dc:creator>JoelGuerra</dc:creator>
      <dc:date>2014-01-08T17:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating (with Python) a 2nd field based on a 1st field in 10.2</title>
      <link>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541754#M42296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This doesn't account for multiples of the same value, but it'd work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;table = "my_table"
field_to_sort = "a"
field_to_rank = "b"

# Make a sorted set of values in table
with arcpy.da.cursor(table, field_to_sort) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; sorted_items = sorted( { row[0] for row in cursor } )

# Rank based on order
sorted_ranking = { item: index + 1 for index, item in enumerate(sorted_items) }

with arcpy.da.UpdateCursor(table, [field_to_sort, field_to_rank]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for value, rank_value in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_rank_value = sorted_ranking[value]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow([value, new_rank_value])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:29:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541754#M42296</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T23:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating (with Python) a 2nd field based on a 1st field in 10.2</title>
      <link>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541755#M42297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'll certainly give this a try. Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jan 2014 18:00:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541755#M42297</guid>
      <dc:creator>JoelGuerra</dc:creator>
      <dc:date>2014-01-08T18:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating (with Python) a 2nd field based on a 1st field in 10.2</title>
      <link>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541756#M42298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Looking it over I noticed the work space was not set. I'm assuming the code here comes after the workspace is set right? Sorry, I'm a newbie to Python. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jan 2014 10:37:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541756#M42298</guid>
      <dc:creator>JoelGuerra</dc:creator>
      <dc:date>2014-01-09T10:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating (with Python) a 2nd field based on a 1st field in 10.2</title>
      <link>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541757#M42299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When running the script, it seems to have a problem with one of the lines. This is the error that is coming up;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with arcpy.da.cursor(table, field_to_sort) as cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Attribute Error: 'module' object has no attribute 'cursor'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just a reminder also, the "field_to_rank" variable is one that needs to be created in the table.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jan 2014 12:51:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541757#M42299</guid>
      <dc:creator>JoelGuerra</dc:creator>
      <dc:date>2014-01-09T12:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating (with Python) a 2nd field based on a 1st field in 10.2</title>
      <link>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541758#M42300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also when entering the table in question (the table that is supposed to have its fields sorted), can I just put in/reference the shape file itself, or does it needs to be an actual excel or dbf table?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jan 2014 12:54:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculating-with-python-a-2nd-field-based-on-a-1st/m-p/541758#M42300</guid>
      <dc:creator>JoelGuerra</dc:creator>
      <dc:date>2014-01-09T12:54:53Z</dc:date>
    </item>
  </channel>
</rss>

