<?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 Split one field into multiple based on a delimiter in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25017#M1892</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am looking to split one field (BASE) into four based on a delimiter of ^ such as the following: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"PT COM 790 W INTER W LINE^B&amp;amp;S RR &amp;amp; S LINES SW LESS ^E200&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^WEST"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"PT COM 790 W INTER W LINE" to go to field "Line1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"B&amp;amp;S RR &amp;amp; S LINES SW LESS" to go to field "Line2"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"E200&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " to go to field "Line3"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"WEST" to go to field "Line4"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have searched online and have only seen splits based on X amount of space or only split once, not four times etc. Ex. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Line1 = !BASE!.split(" ", 1)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be great, thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 Mar 2013 14:44:13 GMT</pubDate>
    <dc:creator>jasonheyman</dc:creator>
    <dc:date>2013-03-26T14:44:13Z</dc:date>
    <item>
      <title>Split one field into multiple based on a delimiter</title>
      <link>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25017#M1892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am looking to split one field (BASE) into four based on a delimiter of ^ such as the following: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"PT COM 790 W INTER W LINE^B&amp;amp;S RR &amp;amp; S LINES SW LESS ^E200&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^WEST"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"PT COM 790 W INTER W LINE" to go to field "Line1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"B&amp;amp;S RR &amp;amp; S LINES SW LESS" to go to field "Line2"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"E200&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " to go to field "Line3"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"WEST" to go to field "Line4"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have searched online and have only seen splits based on X amount of space or only split once, not four times etc. Ex. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Line1 = !BASE!.split(" ", 1)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be great, thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Mar 2013 14:44:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25017#M1892</guid>
      <dc:creator>jasonheyman</dc:creator>
      <dc:date>2013-03-26T14:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Split one field into multiple based on a delimiter</title>
      <link>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25018#M1893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jason,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can accomplish this with the following syntax in the field calculator:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!&amp;lt;field name&amp;gt;!.split("^")[0]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Replace &amp;lt;field name&amp;gt; with the field that contains the text.&amp;nbsp; The above would be for field "Line1".&amp;nbsp; For field "Line2" it would be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!&amp;lt;field name&amp;gt;!.split("^")[1]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;....and so forth.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;By default, the split method will split each occurrence of the specified character.&amp;nbsp; You just then need to call each one using it's index.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, be sure you have 'Python' checked at the top of the field calculator.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Mar 2013 15:11:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25018#M1893</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-03-26T15:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Split one field into multiple based on a delimiter</title>
      <link>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25019#M1894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This does appear to work properly until I get to the second occurrence in the field. I assume since I have random spaces in front of the second and third lines, this is causing an issue. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;additional samples of what my original data is like&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ex1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"IRRG 1.13A PT COM 241.50' SE^&amp;nbsp; &amp;amp; 895.12'W INT N LINE SE 1/4 &amp;amp;^&amp;nbsp;&amp;nbsp; CTR LINE SIMMON RD"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ex2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"DEER JUNCTION PLAT IV&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^LOT 7008&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 11:00:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25019#M1894</guid>
      <dc:creator>jasonheyman</dc:creator>
      <dc:date>2013-03-27T11:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Split one field into multiple based on a delimiter</title>
      <link>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25020#M1895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you looking to remove the "&amp;amp;" and spaces?&amp;nbsp; If so, I would recommend running the replace method on your initial field. Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!&amp;lt;field name&amp;gt;!.replace("&amp;amp;", "")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can then run the rstrip and lstrip methods to remove beginning and ending spaces in fields Line1, Line2, etc. after you run the split method.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!&amp;lt;field name&amp;gt;!.rstrip()&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!&amp;lt;field name&amp;gt;!.lstrip()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 12:39:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25020#M1895</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-03-27T12:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Split one field into multiple based on a delimiter</title>
      <link>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25021#M1896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Are you looking to remove the "&amp;amp;" and spaces?&amp;nbsp; If so, I would recommend running the replace method on your initial field. Ex:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!&amp;lt;field name&amp;gt;!.replace("&amp;amp;", "")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;You can then run the rstrip and lstrip methods to remove beginning and ending spaces in fields Line1, Line2, etc. after you run the split method.&amp;nbsp; Ex:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!&amp;lt;field name&amp;gt;!.rstrip()&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!&amp;lt;field name&amp;gt;!.lstrip()&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;No, the intent is to just split them into individual fields, and the code worked for the first word of the series, but when it hits the second word split the code fails.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 17:08:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25021#M1896</guid>
      <dc:creator>jasonheyman</dc:creator>
      <dc:date>2013-04-02T17:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Split one field into multiple based on a delimiter</title>
      <link>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25022#M1897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I understand correctly you want to take one field "A" and create 4 new fields by splitting the contents of "A" based on the "^" symbol?&amp;nbsp; if this is a correct assumption you could do this individually with the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PreLogic Code Block in Python:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def s(a):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; x = a.split('^')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; y = x[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; return y&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;B = s(!A!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This creates a function called s().&amp;nbsp; (a) represents the field that I pass.&amp;nbsp; x = a.split('^') creates a list.&amp;nbsp; y = x[0] assigns the the first value in the list to y.&amp;nbsp; in your case it would be "PT COM 790 W INTER W LINE".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;B= s(!A!) is the original field being pased to the function s()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in your next field you would change y = x[0] to y = x[1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think that this would be easier to automate if you created a stand alone script that accessed your fields by search Cursor, then depending on the length of your list assign it to the appropriate field using an update cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this point you in the right direction.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have attached a photo of my field calculator with the code above.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 20:05:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25022#M1897</guid>
      <dc:creator>JeffPapirtis</dc:creator>
      <dc:date>2013-04-02T20:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Split one field into multiple based on a delimiter</title>
      <link>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25023#M1898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What's the error you receive when you try to execute the code on the second field?&amp;nbsp; You can see a more detailed explanation in the 'Results' window.&amp;nbsp; I could not reproduce this (see screen shots below).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]23155[/ATTACH][ATTACH=CONFIG]23156[/ATTACH][ATTACH=CONFIG]23157[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 10:04:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-one-field-into-multiple-based-on-a-delimiter/m-p/25023#M1898</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-04-03T10:04:06Z</dc:date>
    </item>
  </channel>
</rss>

