<?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: Split values of a field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397960#M31413</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ohhk...&lt;/P&gt;&lt;P&gt;If you could just resolve the "ST/1" related issues with FIND and REPLACE, as mentioned above&lt;/P&gt;&lt;P&gt;then follow the script given below in Python Parser of Field Calculator of a new field (TEST)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;!name!.split("/")[0] + !name![::-1][0:5][::-1]&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 11 Mar 2016 11:20:40 GMT</pubDate>
    <dc:creator>JayantaPoddar</dc:creator>
    <dc:date>2016-03-11T11:20:40Z</dc:date>
    <item>
      <title>Split values of a field</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397954#M31407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;I want to split this values 12345/6789/ST/1 to 12345/ST/1, so i am looking to a formula in a field calculator which can do so.Also for the cases like this 12345/6789/st/1, 12345/6789/st1, 12345/6789/st 1, all this to become 12345/ST/1.&lt;/P&gt;&lt;P&gt;With thanks,&lt;/P&gt;&lt;P&gt;Kelvin.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2016 05:52:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397954#M31407</guid>
      <dc:creator>KelvinMwakomo</dc:creator>
      <dc:date>2016-03-11T05:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a field</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397955#M31408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Kelvin&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;The Python syntax for the Calculate Field tool would be:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;SPLIT1 = !ORIG_FIELD!.split(" ")[0] #0 being the 1st word&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;SPLIT1 = !ORIG_FIELD!.split(" ")[-1] #-1 being the last word&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;Kindly go through below steps also&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;For example, here is a field from some census data I downloaded:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;&lt;A href="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc1.jpg" style="font-family: inherit; font-style: inherit; font-weight: inherit; color: #1982d1;"&gt;&lt;IMG alt="fieldcalc1" class="jive-image alignnone size-full wp-image-936" src="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc1.jpg?w=584" style="border-color: #dddddd; margin-top: 0.4em; padding: 6px;" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;Why did they add the text “Census Tract” to all of these? Seems to be a space waster right? All I really want is just the tract number. So what I will do is create a new field, then calc the value to the 3rd word, or tract number, from the other field.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;First I create a new field named appropriately TRACTNUM. You simply do this using the attribute table window pulldown &amp;gt; Add field…&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;&lt;A href="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc2.jpg" style="font-family: inherit; font-style: inherit; font-weight: inherit; color: #1982d1;"&gt;&lt;IMG alt="fieldcalc2" class="jive-image alignnone size-full wp-image-937" src="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc2.jpg?w=584" style="border-color: #dddddd; margin-top: 0.4em; padding: 6px;" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;Next, I enter the field name, set the type to Text, and set the length to 10.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;&lt;A href="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc3.jpg" style="font-family: inherit; font-style: inherit; font-weight: inherit; color: #1982d1;"&gt;&lt;IMG alt="fieldcalc3" class="wp-image-938 jive-image alignnone size-full" src="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc3.jpg?w=584" style="border-color: #dddddd; margin-top: 0.4em; padding: 6px;" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;My tract numbers will not be longer than 10 characters. Press the OK button and the field will be added to the end of the attribute table.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;Next, I scroll over to the new field name in the attribute table and right click on it to select the field calculator.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;&lt;A href="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc4.jpg" style="font-family: inherit; font-style: inherit; font-weight: inherit; color: #1982d1;"&gt;&lt;IMG alt="fieldcalc4" class="wp-image-939 jive-image alignnone size-full" src="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc4.jpg?w=584" style="border-color: #dddddd; margin-top: 0.4em; padding: 6px;" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;The field calculator appears. I am using ArcMap 10.1, so I select the Python parser, then double click on the NAMELSAD10 field that contains the tract numbers I want to extract, then set the type to String and click on the .split() function. Next in the expression area between () I enter a double quote, a space, and another double quote, then add [2] at the very end. The expression should look like the following:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;&lt;A href="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc5.jpg" style="font-family: inherit; font-style: inherit; font-weight: inherit; color: #1982d1;"&gt;&lt;IMG alt="fieldcalc5" class="jive-image alignnone size-full wp-image-940" src="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc5.jpg?w=584" style="border-color: #dddddd; margin-top: 0.4em; padding: 6px;" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;What this will do is take the text from the NAMELSAD10 field, pass it to the split function which uses the space ” ” as the delimiter to separate the words and then extracts the third word for the TRACTNUM field calculation. In Python, position 0 would be the first word, position 1 the second word, and position 2 the third word, which we want. That is why I used [2].&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;With everything set in the field calculator, click the OK button. Once the calculation is complete, you will see just the tract numbers in the TRACTNUM field.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; margin-bottom: 1.625em; color: #373737;"&gt;&lt;A href="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc6.jpg" style="font-family: inherit; font-style: inherit; font-weight: inherit; color: #1982d1;"&gt;&lt;IMG alt="fieldcalc6" class="wp-image-941 jive-image alignnone size-full" src="http://socalgovgis.files.wordpress.com/2013/12/fieldcalc6.jpg?w=584" style="border-color: #dddddd; margin-top: 0.4em; padding: 6px;" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2016 06:22:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397955#M31408</guid>
      <dc:creator>AbhishekRathi1</dc:creator>
      <dc:date>2016-03-11T06:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a field</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397956#M31409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would rather use &lt;STRONG&gt;Find and Replace&lt;/STRONG&gt; in attribute table&lt;/P&gt;&lt;P&gt;First replace "6789/" with "" (blank).&lt;/P&gt;&lt;P&gt;Then replace "st/1", "st1", "st 1" one after another by "ST/1".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Do take a backup of the data before doing the above activity, since the changes are permanent.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2016 06:42:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397956#M31409</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2016-03-11T06:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a field</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397957#M31410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jayanta,&lt;/P&gt;&lt;P&gt;That was just an example, the real thing was like this below.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="4.JPG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/190737_4.JPG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2016 07:33:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397957#M31410</guid>
      <dc:creator>KelvinMwakomo</dc:creator>
      <dc:date>2016-03-11T07:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a field</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397958#M31411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Abhishek,&lt;/P&gt;&lt;P&gt;What about the 2nd data from last ie.ST also should i write those syntax in series.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2016 07:37:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397958#M31411</guid>
      <dc:creator>KelvinMwakomo</dc:creator>
      <dc:date>2016-03-11T07:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a field</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397959#M31412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Kelvin&lt;/P&gt;&lt;P&gt;Yes &lt;/P&gt;&lt;P&gt;the numric value indicate that the value which is to be seprated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2016 08:11:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397959#M31412</guid>
      <dc:creator>AbhishekRathi1</dc:creator>
      <dc:date>2016-03-11T08:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a field</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397960#M31413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ohhk...&lt;/P&gt;&lt;P&gt;If you could just resolve the "ST/1" related issues with FIND and REPLACE, as mentioned above&lt;/P&gt;&lt;P&gt;then follow the script given below in Python Parser of Field Calculator of a new field (TEST)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;!name!.split("/")[0] + !name![::-1][0:5][::-1]&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2016 11:20:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397960#M31413</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2016-03-11T11:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a field</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397961#M31414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In case that the length of the elements in the string vary, you will need to change the formula that &lt;A href="https://community.esri.com/migrated-users/62883" target="_blank"&gt;Jayanta Poddar&lt;/A&gt; provided to something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;"/".join([!name!.split("/")[0]]+!name!.split("/")[2:])&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just have a look at the following code (especially lines 5 and 6)&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lst = ['18167/23077/ST/1',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '181677/22258/ST/1',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '18168/22142/ST/2',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '181680/22142/ST/1',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '12345/1234/A/1',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '123456/123456/ABC/12']

for name in lst:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print name, '/'.join([name.split('/')[0]]+name.split('/')[2:])
&amp;nbsp;&amp;nbsp;&amp;nbsp; print name, name.split("/")[0] + name[::-1][0:5][::-1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;... and output (especially lines 13+14 and 16+17)&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;18167/23077/ST/1 18167/ST/1
18167/23077/ST/1 18167/ST/1

181677/22258/ST/1 181677/ST/1
181677/22258/ST/1 181677/ST/1

18168/22142/ST/2 18168/ST/2
18168/22142/ST/2 18168/ST/2

181680/22142/ST/1 181680/ST/1
181680/22142/ST/1 181680/ST/1

12345/1234/A/1 12345/A/1
12345/1234/A/1 123454/A/1

123456/123456/ABC/12 123456/ABC/12
123456/123456/ABC/12 123456BC/12&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:11:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-field/m-p/397961#M31414</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T18:11:26Z</dc:date>
    </item>
  </channel>
</rss>

