<?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: Select Unique Combination of Values from Multiple Fields (python) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1253249#M66725</link>
    <description>&lt;P&gt;Thanks Johannes! That worked great!&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2023 13:00:11 GMT</pubDate>
    <dc:creator>JakeNeedle</dc:creator>
    <dc:date>2023-01-31T13:00:11Z</dc:date>
    <item>
      <title>Select Unique Combination of Values from Multiple Fields (python)</title>
      <link>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1252548#M66696</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I'm new to python scripting and I was wondering if there is a way to select features with a unique combination of values from multiple fields. I would like to take each selection set of features and complete additional geoprocessing tasks on them and move on to the next selection of features with the same field values and repeat.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The closest I have got so far is to produce a list of values that are unique in the feature class. I feel like this is not heading in the direction I would like it to. I am open to running the python in or outside of ArcGIS Pro.&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;arcpy&lt;BR /&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;numpy&lt;BR /&gt;&lt;BR /&gt;fc = &lt;SPAN&gt;"C:\Temp\ProjectModel.gdb\TempAvgs_ExportFeatures1"&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;arr = arcpy.da.FeatureClassToNumPyArray(fc&lt;SPAN&gt;, &lt;/SPAN&gt;[&lt;SPAN&gt;'GeologicUnit'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'Analyte'&lt;/SPAN&gt;])&lt;BR /&gt;&lt;BR /&gt;uniqueRows = numpy.unique(arr)&lt;BR /&gt;&lt;SPAN&gt;print &lt;/SPAN&gt;uniqueRows&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 27 Jan 2023 22:15:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1252548#M66696</guid>
      <dc:creator>JakeNeedle</dc:creator>
      <dc:date>2023-01-27T22:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Select Unique Combination of Values from Multiple Fields (python)</title>
      <link>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1252587#M66697</link>
      <description>&lt;P&gt;concatenate the two fields into a new field (comma and or space separated), then export to an array.&amp;nbsp; Bring over the original fields and any other fields that you want for the analysis&lt;/P&gt;&lt;P&gt;Or, you can do the searchcursor thing, or use SplitByAttribute tool if you want to process as separate files (using the new field as the split field)&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/split-by-attributes.htm" target="_blank"&gt;Split By Attributes (Analysis)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But if you aren't working with complex geometry functionality, it is sometimes easier to just do the work in numpy (or even pandas).&amp;nbsp; You can always use arcpy's ExtendTable to bring back tabular results into Pro&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jan 2023 00:26:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1252587#M66697</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-01-28T00:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select Unique Combination of Values from Multiple Fields (python)</title>
      <link>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1252607#M66698</link>
      <description>&lt;P&gt;The arcpy way of doing this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

fc = "C:\Temp\ProjectModel.gdb\TempAvgs_ExportFeatures1"
fields = ['GeologicUnit', 'Analyte']

unique_combinations = {
    row
    for row in arcpy.da.SearchCursor(fc, fields)
    }

for unit, analyte in unique_combinations:
    print(unit, analyte)
    # create a layer with all rows of that values combination
    sql = f"GeologicUnit = {unit} AND Analyte = {analyte}"  # add single quotes around {unit} and {analyte} if those fields are strings
    layer = arcpy.management.MakeFeatureLayer(fc, f"{unit}_{analyte}", sql)
    # do your geoprocessing on this layer
    arcpy.analysis.Intersect([layer, some_other_layer], f"Intersect_{unit}_{analyte}")&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 28 Jan 2023 12:14:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1252607#M66698</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-28T12:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Select Unique Combination of Values from Multiple Fields (python)</title>
      <link>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1253249#M66725</link>
      <description>&lt;P&gt;Thanks Johannes! That worked great!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 13:00:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-unique-combination-of-values-from-multiple/m-p/1253249#M66725</guid>
      <dc:creator>JakeNeedle</dc:creator>
      <dc:date>2023-01-31T13:00:11Z</dc:date>
    </item>
  </channel>
</rss>

