<?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: Calculate fields using first two words from another field arcgis pro in ArcGIS Pro: Partner Solutions Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807665#M14</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG style="background-color: #ffffff; "&gt;&amp;nbsp;Is there a way to write something like an if/else&amp;nbsp;statement to ignore null values, so I just get one word where only one exists and two where two exist?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Index out of range errors are common and the len() method should come in handy for you.&amp;nbsp; Try something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!Field!&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;' '&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;#process as one word&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;#process as multiple words‍‍‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 09:26:18 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2021-12-12T09:26:18Z</dc:date>
    <item>
      <title>Calculate fields using first two words from another field arcgis pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807661#M10</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to use the field calculator to populate a new field with&amp;nbsp;just the first two words from another field.&lt;/P&gt;&lt;P&gt;I can only get the first word, or the second word, but not both to populate the new field. Where am I going wrong with the following code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;!NEWFIELD!.split(&lt;SPAN style="color: #ff0000;"&gt;" "&lt;/SPAN&gt;)[0] + &lt;SPAN style="color: #ff0000;"&gt;"_"&lt;/SPAN&gt; + !NEWFIELD!.split(&lt;SPAN style="color: #ff0000;"&gt;" "&lt;/SPAN&gt;)[1]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #de2900; font-size: xx-small; font-family: Consolas; "&gt;&lt;IMG height="14" src="https://community.esri.com/discussion/Image1.gif" width="14" /&gt;&lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; text-decoration: underline; font-size: xx-small; font-family: Consolas; "&gt;ERROR 000539:&lt;/STRONG&gt;&lt;SPAN style="color: #de2900; font-size: xx-small; font-family: Consolas; "&gt; Traceback (most recent call last): File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;IndexError: list index out of range&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 May 2020 00:45:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807661#M10</guid>
      <dc:creator>JodieRobertson</dc:creator>
      <dc:date>2020-05-31T00:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using first two words from another field arcgis pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807662#M11</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The code as written is using NEWFIELD for the input values, is that what you want?&amp;nbsp; You said you want to "populate a new field with&amp;nbsp;just the first two words from another field," which makes me think NEWFIELD is the field you want to update and not the field you want to get values from.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field names aside, there are a couple of risks with your code:&amp;nbsp; 1) a SQL NULL that gets converted to Python None will generate&amp;nbsp;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;AttributeError: 'NoneType' object has no attribute 'split'&lt;/SPAN&gt;, and 2)&amp;nbsp; a field with only 1 word in it will not have items in the list so retrieving the second item will generate&amp;nbsp;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;IndexError: list index out of range&lt;/SPAN&gt;. &amp;nbsp;&amp;nbsp; I suspect it is that latter issue you are running into.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you sure you don't have any SQL NULLs in the rows you are processing?&amp;nbsp; If you might, you want to add some additional code to check for NULL or you want to pre-select the non-NULL records before running your code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 May 2020 13:36:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807662#M11</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-05-31T13:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using first two words from another field arcgis pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807663#M12</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you are right, the code I had actually been using was !Name!.split(&lt;SPAN style="color: #ff0000;"&gt;" "&lt;/SPAN&gt;)[0] + &lt;SPAN style="color: #ff0000;"&gt;"_"&lt;/SPAN&gt; + !Name!.split(&lt;SPAN style="color: #ff0000;"&gt;" "&lt;/SPAN&gt;)[1], not NEWFIELD, that was a mistake in the question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There was one name with only one word that I had missed, therefore it would have created a NULL value. Is there a way to write something like an if/else&amp;nbsp;statement to ignore null values, so I just get one word where only one exists and two where two exist?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2020 09:43:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807663#M12</guid>
      <dc:creator>JodieRobertson</dc:creator>
      <dc:date>2020-06-02T09:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using first two words from another field arcgis pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807664#M13</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your intent is to get the last name (aka second), then you can do this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# ---- demo&lt;/SPAN&gt;
name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'a'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'a b'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'a b c'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; name&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'a'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'b'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'c'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But if you want to concatenate them, then you can do this&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; name&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'a'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'a b'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'a b'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So the field calculator expression is one of the above like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!name!&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:26:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807664#M13</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-12T09:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using first two words from another field arcgis pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807665#M14</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG style="background-color: #ffffff; "&gt;&amp;nbsp;Is there a way to write something like an if/else&amp;nbsp;statement to ignore null values, so I just get one word where only one exists and two where two exist?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Index out of range errors are common and the len() method should come in handy for you.&amp;nbsp; Try something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!Field!&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;' '&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;#process as one word&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;#process as multiple words‍‍‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:26:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807665#M14</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-12T09:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using first two words from another field arcgis pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807666#M15</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;!Name! &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; !Name! &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; None &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"_"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!Name!&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2020 13:45:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-partner-solutions-questions/calculate-fields-using-first-two-words-from/m-p/807666#M15</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-06-02T13:45:23Z</dc:date>
    </item>
  </channel>
</rss>

