<?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: Concatenating attributes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155479#M11998</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;setting it up as an int first is fine as long as you don't have 1.2 , 1.3 etc then you may want to do&lt;/P&gt;&lt;P&gt;str(int(row[1]*10)) to scale all entries up by 10... you can get stupidly fancy...but always keep stuff simple, there will always be an exception, which others can deal with&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 23 Apr 2016 15:46:36 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-04-23T15:46:36Z</dc:date>
    <item>
      <title>Concatenating attributes</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155474#M11993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Within a chosen shapefile I have the prefix, Area, that needs to be joined to the user specified attribute, chosen as a dropdown from a column within the shapefile. which will become the suffix within a new field.&amp;nbsp; For example, if the user chooses 'gridcode', then the end result should be Area1, Area2, Area3, etc for each of the rows within the Zone attribute column.&amp;nbsp; I have tried to use the CalculateField_management and update cursor, but both gave me errors and since I am relatively new to python, I wanted some input to help me along.&amp;nbsp; Sorry for not inserting the information below in python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Input_Shapefile = arcpy.GetParameterAsText(0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID = arcpy.GetParameterAsText(1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Add Zone&lt;/P&gt;&lt;P&gt;arcpy.AddField_management(Input_Shapefile, "Zone", "TEXT", "20", "2", "20", "", "NULLABLE", "NON_REQUIRED", "")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Process: Name Zones&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(Input_Shapefile, "Zone", 'Area' + str(ID), "PYTHON", "")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Tried to use update cursor, but it created the output as AreaGRIDCODE rather than the gridcode values&lt;/P&gt;&lt;P&gt;# with arcpy.da.UpdateCursor(Input_Shapefile, "Zone") as cursor:&lt;/P&gt;&lt;P&gt;#&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; row.setValue("Zone", 'Area' + str(ID))&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/P&gt;&lt;P&gt;# del cursor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# I found this option below in my searches as it appeared similar to my needs, but still no luck&lt;/P&gt;&lt;P&gt;# ZoneRows = arcpy.UpdateCursor(Input_Shapefile)&lt;/P&gt;&lt;P&gt;# Zones = ZoneRows.next()&lt;/P&gt;&lt;P&gt;# while Zones:&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp; Zones.setValue('Zone', "Area" + str(ID))&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp; ZoneRows.updateRow(Zones)&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp; Zones = ZoneRows.next()&lt;/P&gt;&lt;P&gt;# del Zones, ZoneRows&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Apr 2016 21:30:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155474#M11993</guid>
      <dc:creator>ShawnKasprick</dc:creator>
      <dc:date>2016-04-18T21:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating attributes</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155475#M11994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;when you want to retrieve values from other fields in a row, you need to refer to the row index based on the rows you imported.&amp;nbsp; &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-data-access/updatecursor-class.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-data-access/updatecursor-class.htm"&gt;UpdateCursor—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;So if you import a row and are using two fields in the cursor, then you need to access them as row[0] and row[1] where these represent the columns/fields that you used.&amp;nbsp; The second example in that link uses&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n" style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt;fields&lt;/SPAN&gt;&lt;SPAN style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt; &lt;/SPAN&gt;&lt;SPAN class="o" style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt; &lt;/SPAN&gt;&lt;SPAN class="p" style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt;'WELL_YIELD'&lt;/SPAN&gt;&lt;SPAN class="p" style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt; &lt;/SPAN&gt;&lt;SPAN class="s" style="color: #a31515; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt;'WELL_CLASS'&lt;/SPAN&gt;&lt;SPAN class="p" style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt;]&lt;/SPAN&gt;&lt;SPAN style="color: #4d4d4d; font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-size: 12px; background-color: #fafafa;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;so, row[0] would be 'WELL_YIELD' .&amp;nbsp; there are alternate naming conventions, but I will leave that out for now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS, the simplest way to concatenate with spaces is to ensure that the field values are string, or converted to string, then add a space &lt;/P&gt;&lt;P&gt; str(row[0]) + " " + row[1]&amp;nbsp;&amp;nbsp;&amp;nbsp; ... where row[0] is a number and row[1] is already text.&amp;nbsp; This can also be done with&lt;/P&gt;&lt;P&gt;out = "{ }&amp;nbsp; { }".format(row[0], row[1]) which will handle the string thing and allow you to put in as many spaces and other stuff you want&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Apr 2016 21:47:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155475#M11994</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-04-18T21:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating attributes</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155476#M11995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Considering I will not know the fields of the shapefile being used, I do not think the update cursor will work.&amp;nbsp; If the fields were static, it would be easier to code, however the chosen attribute field could be ID, Gridcode, GRIDCODE, Sample, Number, etc...so I am trying to come up with a better solution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2016 13:27:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155476#M11995</guid>
      <dc:creator>ShawnKasprick</dc:creator>
      <dc:date>2016-04-19T13:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating attributes</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155477#M11996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you don't know the fields or feature class ahead of time use GetParameterAsText, see below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
Input_Shapefile = arcpy.GetParameterAsText(0)
field1 = arcpy.GetParameterAsText(1)#field with wanted attribute
field2 = arcpy.GetParameterAsText(2)#field with wanted attribute
field3 = arcpy.GetParameterAsText(3)#field to update
fields = [field1,field2,field3]
with arcpy.da.UpdateCursor(Input_Shapefile, fields) as rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] =&amp;nbsp; "{ }&amp;nbsp; { }".format(row[0], row[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:15:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155477#M11996</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2021-12-11T08:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating attributes</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155478#M11997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I worked through it and used your example, but it lead me to another problem.&amp;nbsp; The column that was chosen for ZoneID was gridcode which gave me a result of Zone1.0 when I would rather have it as Zone1 so I had to set it up as an integer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Input_Shapefile = arcpy.GetParameterAsText(0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ZoneID = arcpy.GetParameterAsText(1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fields = ['Area', ZoneID]&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor(Input_Shapefile, fields) as cursor:&lt;/P&gt;&lt;P&gt;&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; row[0] = 'Zone' + str(int(row[1]))&lt;/P&gt;&lt;P&gt;&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>Sat, 23 Apr 2016 15:02:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155478#M11997</guid>
      <dc:creator>ShawnKasprick</dc:creator>
      <dc:date>2016-04-23T15:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating attributes</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155479#M11998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;setting it up as an int first is fine as long as you don't have 1.2 , 1.3 etc then you may want to do&lt;/P&gt;&lt;P&gt;str(int(row[1]*10)) to scale all entries up by 10... you can get stupidly fancy...but always keep stuff simple, there will always be an exception, which others can deal with&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Apr 2016 15:46:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-attributes/m-p/155479#M11998</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-04-23T15:46:36Z</dc:date>
    </item>
  </channel>
</rss>

