<?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 Two Part Street Names into a single field? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1225042#M65931</link>
    <description>&lt;P&gt;You probably won't find ESRI documentation for split(), as that's a basic Pythonj function, not something ESRI developed.&lt;/P&gt;&lt;P&gt;split() takes a string and splits it at the given character. Optionally, you can tell it how many splits to do. It outputs a list.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"this is a string".split(" ")
# ['this', 'is', 'a', 'string']

"this is a string".split(" ", 1)
# ['this', 'is a string']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The official documentation is here (scroll to str.split): &lt;A href="https://docs.python.org/3.3/library/stdtypes.html?highlight=split#string-methods" target="_blank"&gt;4. Built-in Types — Python 3.3.7 documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;An easier documentation is here:&amp;nbsp;&lt;A href="https://www.w3schools.com/python/ref_string_split.asp" target="_blank"&gt;Python String split() Method (w3schools.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A list is a collection of elements that you can address by using their position in the collection (their index). Examples can be found here:&amp;nbsp;&lt;A href="https://railsware.com/blog/python-for-machine-learning-indexing-and-slicing-for-lists-tuples-strings-and-other-sequential-types/" target="_blank"&gt;Python Indexing and Slicing for Lists and other Sequential Types | Railsware Blog&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for your problem: Yes, do field calculations for the two fields.&lt;/P&gt;&lt;P&gt;For the field that contains the road type:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;!Street_Name!.split(" ")[-1]&lt;/LI-CODE&gt;&lt;P&gt;This will get the last element of the split name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the field that contains the name:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;" ".join(!Street_Name!.split(" ")[:-1])&lt;/LI-CODE&gt;&lt;P&gt;This gets all elements of the split name, up to (excluding) the last. Then it joins those elements together into a single string (the opposite of split()).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"San Marino Dr".split(" ")[-1]
# 'Dr'

" ".join("San Marino Dr".split(" ")[:-1])
# 'San Marino'&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 25 Oct 2022 05:14:36 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-10-25T05:14:36Z</dc:date>
    <item>
      <title>Split Two Part Street Names into a single field?</title>
      <link>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1225029#M65930</link>
      <description>&lt;P&gt;I am new to python.&lt;/P&gt;&lt;P&gt;I have encountered this situation, with about 1,000 street names that look like this in the single streetname field of my feature class:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;San Marino Dr&lt;/P&gt;&lt;P&gt;El Cajon St&lt;/P&gt;&lt;P&gt;San Andreas St&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I split "San Marino Dr" into 2 separate fields, one field will contain "San Marino" and the other field will contain "Dr"? Would it be easier to do a field calculate on each of the two fields I plan to split the streetname into?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doing a field calculate on a new empty field named Street1, here is where I get stuck:&lt;/P&gt;&lt;P&gt;!Street_Name!.split(" ")[0]&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will give me "San", but how do I get "Marino"?&lt;/P&gt;&lt;P&gt;My second related question, where do I find a good Pro Resource for showing how to use ".split()" in Python?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 02:57:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1225029#M65930</guid>
      <dc:creator>TimHayes3</dc:creator>
      <dc:date>2022-10-25T02:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Split Two Part Street Names into a single field?</title>
      <link>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1225042#M65931</link>
      <description>&lt;P&gt;You probably won't find ESRI documentation for split(), as that's a basic Pythonj function, not something ESRI developed.&lt;/P&gt;&lt;P&gt;split() takes a string and splits it at the given character. Optionally, you can tell it how many splits to do. It outputs a list.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"this is a string".split(" ")
# ['this', 'is', 'a', 'string']

"this is a string".split(" ", 1)
# ['this', 'is a string']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The official documentation is here (scroll to str.split): &lt;A href="https://docs.python.org/3.3/library/stdtypes.html?highlight=split#string-methods" target="_blank"&gt;4. Built-in Types — Python 3.3.7 documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;An easier documentation is here:&amp;nbsp;&lt;A href="https://www.w3schools.com/python/ref_string_split.asp" target="_blank"&gt;Python String split() Method (w3schools.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A list is a collection of elements that you can address by using their position in the collection (their index). Examples can be found here:&amp;nbsp;&lt;A href="https://railsware.com/blog/python-for-machine-learning-indexing-and-slicing-for-lists-tuples-strings-and-other-sequential-types/" target="_blank"&gt;Python Indexing and Slicing for Lists and other Sequential Types | Railsware Blog&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for your problem: Yes, do field calculations for the two fields.&lt;/P&gt;&lt;P&gt;For the field that contains the road type:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;!Street_Name!.split(" ")[-1]&lt;/LI-CODE&gt;&lt;P&gt;This will get the last element of the split name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the field that contains the name:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;" ".join(!Street_Name!.split(" ")[:-1])&lt;/LI-CODE&gt;&lt;P&gt;This gets all elements of the split name, up to (excluding) the last. Then it joins those elements together into a single string (the opposite of split()).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"San Marino Dr".split(" ")[-1]
# 'Dr'

" ".join("San Marino Dr".split(" ")[:-1])
# 'San Marino'&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 25 Oct 2022 05:14:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1225042#M65931</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-10-25T05:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Split Two Part Street Names into a single field?</title>
      <link>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1225184#M65934</link>
      <description>&lt;P&gt;This is a perfect answer. However, I want to add something that I found in our organization while doing something similar. We have some streets that don't have a street suffix. You should make sure that scenario does not exist or code to handle it.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 14:11:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1225184#M65934</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-10-25T14:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Split Two Part Street Names into a single field?</title>
      <link>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1226236#M65960</link>
      <description>&lt;P&gt;Thank you, Johannes! this was super helpful. Exactly what I was looking for.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 16:41:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/split-two-part-street-names-into-a-single-field/m-p/1226236#M65960</guid>
      <dc:creator>TimHayes3</dc:creator>
      <dc:date>2022-10-27T16:41:56Z</dc:date>
    </item>
  </channel>
</rss>

