<?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: arcpy function for attributes in a field? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191852#M14772</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's how to do it a search cursor (very quickly, compared to the Frequency or Statistics tools) -- if what you want is Python list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def ListUnique(tbl, field):
&amp;nbsp;&amp;nbsp;&amp;nbsp; vlist = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(tbl, field) as rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vlist.append(row[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; return sorted(list(set(vlist))) # unique-ize and sort the list
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that you don't need to sort the list if you don't need to:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; list(set([3,2,1,4,3,99, 98]))
[1, 2, 99, 4, 98, 3]&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;([LISTUNIQUE] was a very often-used function back in AML pre-history. Those were the days, my friends...)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 09:39:13 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-11T09:39:13Z</dc:date>
    <item>
      <title>arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191843#M14763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a function in arcpy that will list all the different individual attributes in a field? I know I have seen this somewhere but can't remember, or find it.&amp;nbsp; I want to create a script to export data in a fc based on attributes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 May 2015 19:28:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191843#M14763</guid>
      <dc:creator>BradJones</dc:creator>
      <dc:date>2015-05-17T19:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191844#M14764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;are you referring to either Summary Statistics or the Split Tool​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 May 2015 21:31:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191844#M14764</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-17T21:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191845#M14765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Summary Statistics would be the starting point for your script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.Statistics_analysis("DevTypes","C:/Users/Owen/Documents/ArcGIS/Default.gdb/DevTypes_Stats","OBJECTID FIRST","ClassCode")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are only interested in the unique values in a field then use it as the Case Field parameter. For the Statistics Field(s) parameter you can just use the first ObjectId (the output for this is not used but it is a required input). You will end up with something like:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="summary-stats.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/100237_summary-stats.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;Then you can use a search cursor to loop through the field values for the export stage.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 May 2015 22:02:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191845#M14765</guid>
      <dc:creator>OwenEarley</dc:creator>
      <dc:date>2015-05-17T22:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191846#M14766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​Neither I believe. If I'm not mistaken the summary statistics tool will not provide a list of atributes (strings) in a field and e split tool requires a second feature to base the split on, as well as a field. Am I wrong?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 May 2015 22:06:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191846#M14766</guid>
      <dc:creator>BradJones</dc:creator>
      <dc:date>2015-05-17T22:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191847#M14767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​A coworker asked me about this ( he doesn't know Python) and I said it would require a python script with a search curso. But I remember being shown a way to produce a list of attributes from a field. I thought it was an arcpy function. Then a "for" loop could be used to loop through the attributes for the export. Just a thought. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 May 2015 22:25:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191847#M14767</guid>
      <dc:creator>BradJones</dc:creator>
      <dc:date>2015-05-17T22:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191848#M14768</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Several approaches work.&amp;nbsp; ModelBuilder does this with a &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00400000000t000000"&gt;Iterate Field Values iterator&lt;/A&gt; with the Unique Value option checked.&amp;nbsp; The iterator provides the current value being processed in a variable that can be used to name files using Feature Class to Feature Class for an export.&amp;nbsp; All of the steps can be done through a model without any Python scripting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Summary Statistics works also, because it exactly provides a list of strings from a source text field into a new text field with only the sorted, unique values listed if you use that field as the Case field as Owen suggested.&amp;nbsp; This can be output to an in memory output in a script if you just want to read the values for naming files.&amp;nbsp;&amp;nbsp; A second for loop with a cursor would read the list and use a tool like Feature Class to Feature Class to export each file and do the naming.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A cursor can do this also, but it is not an absolute requirement to take that approach.&amp;nbsp; It is done with two for loops.&amp;nbsp; A search cursor for loop would read the values into a list which could be sorted with the sort function and then made unique using the set function, then a second for loop would read the list and use a tool like Feature Class to Feature Class to export each file and do the naming.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the end goal is simply to create a table of unique values in a field all you need is the Summary Statistics tool as everyone else has said.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the goal is to create a single feature based on each of the unique attributes in a field use Dissolve with the Case Field assigned and the create multi-part features option checked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 May 2015 23:20:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191848#M14768</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-05-17T23:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191849#M14769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;summary statistics ... the tool in arctoolbox, will give you what you need, or you can extract the necessary code from my&lt;A href="http://www.arcgis.com/home/item.html?id=6c384f06c9f14d09920f4ff14460f4e2"&gt; Field Statistics Toolbox..&lt;/A&gt;&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 May 2015 23:24:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191849#M14769</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-17T23:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191850#M14770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;​Thanks guys. You all were a big help. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 00:49:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191850#M14770</guid>
      <dc:creator>BradJones</dc:creator>
      <dc:date>2015-05-18T00:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191851#M14771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No offense meant to Richard, but I'm wondering why you marked his response as the answer, when two people had already told you about the summary statistics function, one of them twice.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 03:07:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191851#M14771</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-05-18T03:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191852#M14772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's how to do it a search cursor (very quickly, compared to the Frequency or Statistics tools) -- if what you want is Python list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def ListUnique(tbl, field):
&amp;nbsp;&amp;nbsp;&amp;nbsp; vlist = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(tbl, field) as rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vlist.append(row[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; return sorted(list(set(vlist))) # unique-ize and sort the list
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that you don't need to sort the list if you don't need to:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; list(set([3,2,1,4,3,99, 98]))
[1, 2, 99, 4, 98, 3]&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;([LISTUNIQUE] was a very often-used function back in AML pre-history. Those were the days, my friends...)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:39:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191852#M14772</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T09:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy function for attributes in a field?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191853#M14773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 13:19:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-function-for-attributes-in-a-field/m-p/191853#M14773</guid>
      <dc:creator>BradJones</dc:creator>
      <dc:date>2015-05-18T13:19:41Z</dc:date>
    </item>
  </channel>
</rss>

