<?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 Why does my calculate field script remove the underscore in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/why-does-my-calculate-field-script-remove-the/m-p/1390518#M70006</link>
    <description>&lt;P&gt;I am going to try and keep this simple.&lt;/P&gt;&lt;P&gt;I am pulling information from table A which has a text field with numbers like this 1119_232.2_93.2.&lt;/P&gt;&lt;P&gt;I get this information by using arcpy.da.Searchcursor._as_narray(). I then access the item from the array and save it as a string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then my script runs the calculate field tool which calculates a specific field based on the string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I specifically send the numbers in as a string by using str()&lt;/P&gt;&lt;P&gt;However without fail every time it removes the "_" and write the numbers to the TEXT field as 1110232.293.2&lt;/P&gt;&lt;P&gt;parcels = "Parcels (Block and Lot) Data - For Internal Purposes Only - Do Not Distribute"&lt;BR /&gt;i = 0&lt;BR /&gt;cursor = arcpy.da.SearchCursor(Geocode, ["ObjectID"])&lt;BR /&gt;array = cursor._as_narray()&lt;BR /&gt;while i &amp;lt; len(array):&lt;BR /&gt;&amp;nbsp; arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "ObjectID = " + str(array[i][0]))&lt;BR /&gt;&amp;nbsp; arcpy.management.SelectLayerByLocation(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; in_layer="'Parcels (Block and Lot) Data - For Internal Purposes Only - Do Not Distribute'",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; overlap_type="INTERSECT",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; select_features="CSRR_PI_Coords_Geocoded",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; search_distance=None,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; selection_type="NEW_SELECTION",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; invert_spatial_relationship="NOT_INVERT"&lt;BR /&gt;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; pcursor = arcpy.da.SearchCursor(parcels, ["Pams_Pin"])&lt;BR /&gt;&amp;nbsp; parray = pcursor._as_narray()&lt;BR /&gt;&amp;nbsp; string = str(parray[0][0])&lt;BR /&gt;&amp;nbsp; splstr = string.split("_")&lt;BR /&gt;&amp;nbsp; t = 1&lt;BR /&gt;&amp;nbsp; concat = splstr[0]&lt;BR /&gt;&amp;nbsp; if len(splstr) &amp;gt; 3:&lt;BR /&gt;&amp;nbsp; while t &amp;lt; len(splstr) - 1:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; concat += "_" + splstr[t]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; t += 1&lt;BR /&gt;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; while t &amp;lt; len(splstr):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; concat += "_" + splstr[t]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; t += 1&lt;BR /&gt;&amp;nbsp; print(concat)&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.management.CalculateField(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; in_table=Geocode,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; field = "USER_parcel_data",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; expression = str(concat),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; expression_type = "PYTHON3",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; code_block = "",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; field_type = "TEXT",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; enforce_domains = "NO_ENFORCE_DOMAINS"&lt;BR /&gt;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; i += 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am about to save each spot in the array to its own field ie array[0] to Field A, array[1] to Field B, array[2] to Field C. then Calculate the field as FieldA + "_" + FieldB + "_" + FieldC&lt;/P&gt;&lt;P&gt;However that will add run time and I have this looping through 2500 features&lt;/P&gt;</description>
    <pubDate>Mon, 04 Mar 2024 16:57:48 GMT</pubDate>
    <dc:creator>BrandonMcAlister</dc:creator>
    <dc:date>2024-03-04T16:57:48Z</dc:date>
    <item>
      <title>Why does my calculate field script remove the underscore</title>
      <link>https://community.esri.com/t5/python-questions/why-does-my-calculate-field-script-remove-the/m-p/1390518#M70006</link>
      <description>&lt;P&gt;I am going to try and keep this simple.&lt;/P&gt;&lt;P&gt;I am pulling information from table A which has a text field with numbers like this 1119_232.2_93.2.&lt;/P&gt;&lt;P&gt;I get this information by using arcpy.da.Searchcursor._as_narray(). I then access the item from the array and save it as a string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then my script runs the calculate field tool which calculates a specific field based on the string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I specifically send the numbers in as a string by using str()&lt;/P&gt;&lt;P&gt;However without fail every time it removes the "_" and write the numbers to the TEXT field as 1110232.293.2&lt;/P&gt;&lt;P&gt;parcels = "Parcels (Block and Lot) Data - For Internal Purposes Only - Do Not Distribute"&lt;BR /&gt;i = 0&lt;BR /&gt;cursor = arcpy.da.SearchCursor(Geocode, ["ObjectID"])&lt;BR /&gt;array = cursor._as_narray()&lt;BR /&gt;while i &amp;lt; len(array):&lt;BR /&gt;&amp;nbsp; arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "ObjectID = " + str(array[i][0]))&lt;BR /&gt;&amp;nbsp; arcpy.management.SelectLayerByLocation(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; in_layer="'Parcels (Block and Lot) Data - For Internal Purposes Only - Do Not Distribute'",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; overlap_type="INTERSECT",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; select_features="CSRR_PI_Coords_Geocoded",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; search_distance=None,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; selection_type="NEW_SELECTION",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; invert_spatial_relationship="NOT_INVERT"&lt;BR /&gt;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; pcursor = arcpy.da.SearchCursor(parcels, ["Pams_Pin"])&lt;BR /&gt;&amp;nbsp; parray = pcursor._as_narray()&lt;BR /&gt;&amp;nbsp; string = str(parray[0][0])&lt;BR /&gt;&amp;nbsp; splstr = string.split("_")&lt;BR /&gt;&amp;nbsp; t = 1&lt;BR /&gt;&amp;nbsp; concat = splstr[0]&lt;BR /&gt;&amp;nbsp; if len(splstr) &amp;gt; 3:&lt;BR /&gt;&amp;nbsp; while t &amp;lt; len(splstr) - 1:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; concat += "_" + splstr[t]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; t += 1&lt;BR /&gt;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; while t &amp;lt; len(splstr):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; concat += "_" + splstr[t]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; t += 1&lt;BR /&gt;&amp;nbsp; print(concat)&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.management.CalculateField(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; in_table=Geocode,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; field = "USER_parcel_data",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; expression = str(concat),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; expression_type = "PYTHON3",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; code_block = "",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; field_type = "TEXT",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; enforce_domains = "NO_ENFORCE_DOMAINS"&lt;BR /&gt;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; i += 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am about to save each spot in the array to its own field ie array[0] to Field A, array[1] to Field B, array[2] to Field C. then Calculate the field as FieldA + "_" + FieldB + "_" + FieldC&lt;/P&gt;&lt;P&gt;However that will add run time and I have this looping through 2500 features&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:57:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-my-calculate-field-script-remove-the/m-p/1390518#M70006</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-03-04T16:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why does my calculate field script remove the underscore</title>
      <link>https://community.esri.com/t5/python-questions/why-does-my-calculate-field-script-remove-the/m-p/1391150#M70012</link>
      <description>&lt;P&gt;I have a solution!&lt;BR /&gt;&lt;BR /&gt;I was sending the numbers through as a string but when the numbers were being sent through the calculate field script the did not have quotation marks attached to them.&lt;/P&gt;&lt;P&gt;I used the Geoprocessing pane to test. I sent the numbers through like this "1010_232_98.2" and it wrote correctly to the field with the underscores _ . I then use the Geoprocessing pace to send the numbers through like this 1010_232_98.2 and it wrote to the field without the underscores _.&lt;/P&gt;&lt;P&gt;I have since adjusted the code to look like this&lt;/P&gt;&lt;P&gt;parcels = "Parcels (Block and Lot) Data - For Internal Purposes Only - Do Not Distribute"&lt;BR /&gt;i = 0&lt;BR /&gt;cursor = arcpy.da.SearchCursor(Geocode, ["ObjectID"])&lt;BR /&gt;array = cursor._as_narray()&lt;BR /&gt;while i &amp;lt; len(array):&lt;BR /&gt;&amp;nbsp; arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "ObjectID = " + str(array[i][0]))&lt;BR /&gt;&amp;nbsp; arcpy.management.SelectLayerByLocation(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; in_layer="'Parcels (Block and Lot) Data - For Internal Purposes Only - Do Not Distribute'",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; overlap_type="INTERSECT",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; select_features="CSRR_PI_Coords_Geocoded",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; search_distance=None,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; selection_type="NEW_SELECTION",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; invert_spatial_relationship="NOT_INVERT"&lt;BR /&gt;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; pcursor = arcpy.da.SearchCursor(parcels, ["Pams_Pin"])&lt;BR /&gt;&amp;nbsp; parray = pcursor._as_narray()&lt;BR /&gt;&amp;nbsp; string = parray[0][0]&lt;/P&gt;&lt;P&gt;&amp;nbsp; tada = ' " ' + string + ' " ' # This appends quotation marks to the numbers so it can be sent through the calculate field tool with " " attached&lt;/P&gt;&lt;P&gt;&amp;nbsp; arcpy.management.CalculateField(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; in_table=Geocode,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; field = "USER_parcel_data",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; expression = tada,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; expression_type = "PYTHON3",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; code_block = "",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; field_type = "TEXT",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; enforce_domains = "NO_ENFORCE_DOMAINS"&lt;BR /&gt;&amp;nbsp; )&lt;BR /&gt;&amp;nbsp; i += 1&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 15:33:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-my-calculate-field-script-remove-the/m-p/1391150#M70012</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-03-05T15:33:04Z</dc:date>
    </item>
  </channel>
</rss>

