<?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: Rank values in a field using python in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/rank-values-in-a-field-using-python/m-p/74567#M2616</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I believe you need to use a cursor to pass the values one at a time. To read fields values, use &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000039000000.htm"&gt;SearchCursor&lt;/A&gt;&lt;SPAN&gt;. To write values, use &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/UpdateCursor/000v0000003m000000/"&gt;UpdateCursor&lt;/A&gt;&lt;SPAN&gt; or &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/InsertCursor/000v00000038000000/"&gt;InsertCursor&lt;/A&gt;&lt;SPAN&gt;. Make sure you take advantage of the sorting capabilities, especially for your ranking question.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS - there's a forum specifically for Python, where you'll probably get your questions answered faster.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Apr 2011 15:10:13 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2011-04-15T15:10:13Z</dc:date>
    <item>
      <title>Rank values in a field using python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/rank-values-in-a-field-using-python/m-p/74566#M2615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to take values in one field and write the ranks for those values to a new field.&amp;nbsp; For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3 -&amp;gt; 2 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 -&amp;gt; 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5 -&amp;gt; 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6 -&amp;gt; 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;9 -&amp;gt; 6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;7 -&amp;gt; 5&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In an ideal world, I'd like to deal with ties in a particular way (as follows), but one step at a time...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3 -&amp;gt; 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 -&amp;gt; 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 -&amp;gt; 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 -&amp;gt; 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5 -&amp;gt; 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;9 -&amp;gt; 5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;7 -&amp;gt; 4&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using numpy and scipy, I have gotten this to work using just Python (PythonWin), outside of ArcMap.&amp;nbsp; The following averages the ranks of ties, which is good enough for now:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import numpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import scipy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from scipy import stats&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;x=numpy.ma.array([0,1,1,1,2,2,4,4,5,6])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rank = stats.mstats.rankdata(&lt;X&gt;)&lt;/X&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print rank&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Results in:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[[&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp; 5.5&amp;nbsp;&amp;nbsp; 5.5&amp;nbsp;&amp;nbsp; 7.5&amp;nbsp;&amp;nbsp; 7.5&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp; 10 ]]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At this point, i am trying to figure out how to pass values from a field into the input array and then write the results back to the other field.&amp;nbsp; I'm not sure if a cursor is the best way to do this, or if all the values in a field can be passed into an array.&amp;nbsp; Again, I'm a python newbie, so any ideas or suggestions are welcome.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Erik&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Apr 2011 14:34:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/rank-values-in-a-field-using-python/m-p/74566#M2615</guid>
      <dc:creator>ErikMartin</dc:creator>
      <dc:date>2011-04-15T14:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: Rank values in a field using python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/rank-values-in-a-field-using-python/m-p/74567#M2616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I believe you need to use a cursor to pass the values one at a time. To read fields values, use &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000039000000.htm"&gt;SearchCursor&lt;/A&gt;&lt;SPAN&gt;. To write values, use &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/UpdateCursor/000v0000003m000000/"&gt;UpdateCursor&lt;/A&gt;&lt;SPAN&gt; or &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/InsertCursor/000v00000038000000/"&gt;InsertCursor&lt;/A&gt;&lt;SPAN&gt;. Make sure you take advantage of the sorting capabilities, especially for your ranking question.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS - there's a forum specifically for Python, where you'll probably get your questions answered faster.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Apr 2011 15:10:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/rank-values-in-a-field-using-python/m-p/74567#M2616</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2011-04-15T15:10:13Z</dc:date>
    </item>
  </channel>
</rss>

