<?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 name filed in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189435#M64918</link>
    <description>&lt;P&gt;I was able to get the first and last string. Not sure how to get the middle&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MariyanaKostov1_1-1657031671499.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/45205i9964EF21C0F14056/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MariyanaKostov1_1-1657031671499.png" alt="MariyanaKostov1_1-1657031671499.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>Tue, 05 Jul 2022 14:34:38 GMT</pubDate>
    <dc:creator>MariyanaKostov1</dc:creator>
    <dc:date>2022-07-05T14:34:38Z</dc:date>
    <item>
      <title>Split values of a name filed</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189405#M64910</link>
      <description>&lt;P&gt;I have a filed containing first, middle, and last name Ex:Emily Smith Brannen.&lt;/P&gt;&lt;P&gt;I want each name in a different field. In other word: the siring before the first space in one filed, the string between first and second space in another field, and the string before the last space in a third field.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="39032725-49e9-4453-b860-5414d971f3df.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/45198i8D0C2B80A3EEB689/image-size/medium?v=v2&amp;amp;px=400" role="button" title="39032725-49e9-4453-b860-5414d971f3df.png" alt="39032725-49e9-4453-b860-5414d971f3df.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 302px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/45199i25ACF7DFC26E0A12/image-dimensions/302x216?v=v2" width="302" height="216" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The script works If I do the calculation on one record but not on the whole filed.&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 14:01:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189405#M64910</guid>
      <dc:creator>MariyanaKostov1</dc:creator>
      <dc:date>2022-07-05T14:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a name filed</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189419#M64913</link>
      <description>&lt;P&gt;strip any potential leading trailing spaces.&amp;nbsp; See the example output below... the last print line is correct,&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for n in name:
    print(n.split(" "))
    print(n.split(" ")[1])
    print(n.strip().split(" ")[1])
    
['a', 'b', 'c']
b
b
['d', 'e', '']
e
e
['', 'f', 'g', 'h', '']
f
g&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 05 Jul 2022 14:20:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189419#M64913</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-07-05T14:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a name filed</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189426#M64915</link>
      <description>&lt;P&gt;Are there any null values in your [Name] column?&amp;nbsp; 'NoneType' objects do not have a 'split' attribute.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 14:27:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189426#M64915</guid>
      <dc:creator>ChrisWiebke</dc:creator>
      <dc:date>2022-07-05T14:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a name filed</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189430#M64916</link>
      <description>&lt;P&gt;How do I check for null values? Our secretary typed in the names so I don't know if she typed any 'crazy' values:-)&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 14:32:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189430#M64916</guid>
      <dc:creator>MariyanaKostov1</dc:creator>
      <dc:date>2022-07-05T14:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a name filed</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189434#M64917</link>
      <description>&lt;P&gt;That could be a lot things causing that error.&amp;nbsp; Since it looks like the names do not contain all three (first, middle, last), you need to account for those like Clint. You can do that with using a function.&amp;nbsp; Make sure python is checked, and Show Codeblock is checked. If there are only two, like Clint, youll need to skip the middle name because Shugart is probably their last name.&amp;nbsp; Indenting counts here, and can be a pain so make sure you use 4 spaces per indent if the code doesn't copy paste correctly.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fieldcalc_First.png" style="width: 464px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/45201iA44BA196ADD3BE64/image-size/large?v=v2&amp;amp;px=999" role="button" title="fieldcalc_First.png" alt="fieldcalc_First.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def namesplit(name):
    splt = name.split(' ')
    if splt[0]:
        return splt[0]
    else:
        return None

# and in the FirstName block:
namesplit(!Name!)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="fieldcalc_Middle.png" style="width: 467px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/45202i786F68B7DA305502/image-size/large?v=v2&amp;amp;px=999" role="button" title="fieldcalc_Middle.png" alt="fieldcalc_Middle.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def namesplit(st_name):
    splt = st_name.split(' ')
    if len(splt) &amp;gt; 2:
        if splt[1]:
            return splt[1]
    else:
       return None&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and last name code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def namesplit(st_name):
    splt = st_name.split(' ')
    if len(splt) == 2:
        if splt[1]:
            return splt[1]
    elif  len(splt) &amp;gt; 2:
        if splt[2]:
            return splt[2:]
    else:
        return None&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;added return splt[2:] to capture the Sr, Jr, etc.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 15:09:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189434#M64917</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-05T15:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a name filed</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189435#M64918</link>
      <description>&lt;P&gt;I was able to get the first and last string. Not sure how to get the middle&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MariyanaKostov1_1-1657031671499.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/45205i9964EF21C0F14056/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MariyanaKostov1_1-1657031671499.png" alt="MariyanaKostov1_1-1657031671499.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>Tue, 05 Jul 2022 14:34:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189435#M64918</guid>
      <dc:creator>MariyanaKostov1</dc:creator>
      <dc:date>2022-07-05T14:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Split values of a name filed</title>
      <link>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189445#M64920</link>
      <description>&lt;LI-CODE lang="python"&gt;def split_name(name):
    """splits a name (str) into 3 parts (first, middle, last)"""
    try:
        name_parts = name.strip().split(" ")
    except AttributeError:
        # handle non-strings
        return [None, None, None]
    first = name_parts[0]
    last = name_parts[-1]
    middle = " ".join(name_parts[1:-1])
    if middle == "":
        middle = None
    return [first, middle, last]


split_name('David Smith')
#['David', None, 'Smith']

split_name('David "The cooler David" Johnson')
#['David', '"The cooler David"', 'Johnson']

split_name("Clinton B Brennan")
#['Clinton', 'B', 'Brennan']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use that function as code block and these expressions to calculate the fields:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FirstName = split_name(!Name!)[0]
MiddleName = split_name(!Name!)[1]
LastName = split_name(!Name!)[2]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 14:52:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-values-of-a-name-filed/m-p/1189445#M64920</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-07-05T14:52:29Z</dc:date>
    </item>
  </channel>
</rss>

