<?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: Help with inconsistent indexing in a field. in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-inconsistent-indexing-in-a-field/m-p/1506746#M85714</link>
    <description>&lt;P&gt;UPDATE: I was able to get it to work....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;# Define the shapefile path&lt;BR /&gt;shapefile_path = r""&lt;/P&gt;&lt;P&gt;# Add a new field called "VERSION" to the shapefile&lt;BR /&gt;arcpy.AddField_management(shapefile_path, "VERSION", "TEXT")&lt;/P&gt;&lt;P&gt;# Update the "VERSION" field based on the "DUE_TIME" field&lt;BR /&gt;with arcpy.da.UpdateCursor(shapefile_path, ["DUE_TIME", "VERSION"]) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;# Split the "DUE_TIME" value by space&lt;BR /&gt;due_time_parts = row[0].split(" ")&lt;BR /&gt;&lt;BR /&gt;# Check if the value at index 1 exists&lt;BR /&gt;if len(due_time_parts) &amp;gt; 1:&lt;BR /&gt;# If it exists, set the "VERSION" field to the value at index 1&lt;BR /&gt;row[1] = due_time_parts[1]&lt;BR /&gt;else:&lt;BR /&gt;# If it does not exist, set the "VERSION" field to "0"&lt;BR /&gt;row[1] = "0"&lt;BR /&gt;&lt;BR /&gt;# Update the row&lt;BR /&gt;cursor.updateRow(row)&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2024 17:10:55 GMT</pubDate>
    <dc:creator>gmaurer1123</dc:creator>
    <dc:date>2024-07-18T17:10:55Z</dc:date>
    <item>
      <title>Help with inconsistent indexing in a field.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-inconsistent-indexing-in-a-field/m-p/1506715#M85708</link>
      <description>&lt;P&gt;Hello All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to Python and struggling. Please see the screenshot below.&amp;nbsp; I have a text column&amp;nbsp;(i.e. DUE_TIME) in a given shapefile that I need to split into a new field (i.e. VERSION). The problem I am having is that the original field (i.e. DUE_TIME) may have 1 OR 2 index positions at any given point feature. Some data points may have month/day/year, while others have month/day/year #. So, when I run the script below to try and "split" off the values at index position 1, I get an error stating "Index is out of range" even though some of the rows DO have a value in that index position. In this case, the VERSION field is created, but all rows in that field are blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, I have tried changing the index value in the script to [-1], and while this does split off the # value where it exists, it simply splits off the month/day/year portion where the # does not exist (as seen in the screenshot). I also thought about adding a "0" after month/day year where the # value does not exist, but I am not sure how to write this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to have the DUE_TIME field only contain month/day/year and have the VERSION field only contain # or a 0, if # was not originally present in the DUE_TIME field. I hope my explanation makes sense. Any help will be greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;fc = r"path\DP_Test_SHP"&lt;BR /&gt;arcpy.AddField_management("DP_Test_SHP", "VERSION", "TEXT")&lt;BR /&gt;with arcpy.da.UpdateCursor("DP_Test_SHP", ["DUE_TIME", "VERSION"]) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;row[1] = row[0].split(" ")[-1]&lt;BR /&gt;row=[i.strip() if i is not None else None for i in row]&lt;BR /&gt;cursor.updateRow(row)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gmaurer1123_0-1721318540970.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/110057i5BD232CA6686E9E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gmaurer1123_0-1721318540970.png" alt="gmaurer1123_0-1721318540970.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 16:43:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-inconsistent-indexing-in-a-field/m-p/1506715#M85708</guid>
      <dc:creator>gmaurer1123</dc:creator>
      <dc:date>2024-07-18T16:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help with inconsistent indexing in a field.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-inconsistent-indexing-in-a-field/m-p/1506746#M85714</link>
      <description>&lt;P&gt;UPDATE: I was able to get it to work....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;# Define the shapefile path&lt;BR /&gt;shapefile_path = r""&lt;/P&gt;&lt;P&gt;# Add a new field called "VERSION" to the shapefile&lt;BR /&gt;arcpy.AddField_management(shapefile_path, "VERSION", "TEXT")&lt;/P&gt;&lt;P&gt;# Update the "VERSION" field based on the "DUE_TIME" field&lt;BR /&gt;with arcpy.da.UpdateCursor(shapefile_path, ["DUE_TIME", "VERSION"]) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;# Split the "DUE_TIME" value by space&lt;BR /&gt;due_time_parts = row[0].split(" ")&lt;BR /&gt;&lt;BR /&gt;# Check if the value at index 1 exists&lt;BR /&gt;if len(due_time_parts) &amp;gt; 1:&lt;BR /&gt;# If it exists, set the "VERSION" field to the value at index 1&lt;BR /&gt;row[1] = due_time_parts[1]&lt;BR /&gt;else:&lt;BR /&gt;# If it does not exist, set the "VERSION" field to "0"&lt;BR /&gt;row[1] = "0"&lt;BR /&gt;&lt;BR /&gt;# Update the row&lt;BR /&gt;cursor.updateRow(row)&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 17:10:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-inconsistent-indexing-in-a-field/m-p/1506746#M85714</guid>
      <dc:creator>gmaurer1123</dc:creator>
      <dc:date>2024-07-18T17:10:55Z</dc:date>
    </item>
  </channel>
</rss>

