<?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: Most efficient way to concatenate strings in millions of records ignoring nulls and spaces in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1414978#M82342</link>
    <description>&lt;P&gt;I use this one quite often:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;strval = ' '.join(filter(None, [val1, val2, val3,val4]))&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="RhettZufelt_1-1713989829838.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/102070iC4ABD203CA615C30/image-size/large?v=v2&amp;amp;px=999" role="button" title="RhettZufelt_1-1713989829838.png" alt="RhettZufelt_1-1713989829838.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The space in the single quotes is the delimiter (single space).&amp;nbsp; If any of the val variables have a value, it will be concatenated, but, if Null, will just be ignored without error.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
    <pubDate>Wed, 24 Apr 2024 20:17:23 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2024-04-24T20:17:23Z</dc:date>
    <item>
      <title>Most efficient way to concatenate strings in millions of records ignoring nulls and spaces</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1414863#M82333</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I am trying to concatenate address strings across a dataset that has 3.5 million records. I want to concatenate the values of eight fields into a single string, but many of the fields have null values and many have spaces instead of nulls or extra spaces, etc.&lt;/P&gt;&lt;P&gt;What is the most efficient way in Python or Arcade to join strings ignoring nulls or spaces and just having a single space between the joined values? I usually use a function like " ".join((i for i in (str1,str2,str3) if i)) to do this, but across millions of records I'm hoping to avoid the bottleneck of using an if statement. Also, I'm hoping to avoid having to do trim calculations on each field first. Is there a more efficient way to do this?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 16:58:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1414863#M82333</guid>
      <dc:creator>asmith_tssw</dc:creator>
      <dc:date>2024-04-24T16:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to concatenate strings in millions of records ignoring nulls and spaces</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1414879#M82336</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/466454"&gt;@asmith_tssw&lt;/a&gt;.,&lt;/P&gt;&lt;P&gt;Depending on the method, either python or arcade, you can easily achieve this. You can do something like this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Python:&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Code Expression:
!Concatenation( FieldA , FieldB , FieldC, etc... )!

Code Block:
def Concatenation( FieldA , FieldB , FieldC, etc... ):
    Values = [FieldA , FieldB , FieldC, etc...]
    ConcatNonNullValues = ''.join([ x for x in Values if x is not None ])
    return ConcatNonNullValues&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Arcade:&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ValueList = [ $feature.FieldA , $feature.FieldB, $feature.FieldC, etc... ]
var ConcatValue = ''
for ( var index in ValueList ){
    ListValue = ValueList[ index ]
    if ( IsEmpty( ListValue ) == False ){ ConcatValue + ListValue }
    }
return ConcatValue&lt;/LI-CODE&gt;&lt;P&gt;You can use several arcade functions to make the code above easier, but it depends on how you want to go about it.&lt;/P&gt;&lt;P&gt;Feel free to play around with the code above. It should work for what you need or at least point you in the right direction.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 17:23:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1414879#M82336</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2024-04-24T17:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to concatenate strings in millions of records ignoring nulls and spaces</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1414978#M82342</link>
      <description>&lt;P&gt;I use this one quite often:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;strval = ' '.join(filter(None, [val1, val2, val3,val4]))&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="RhettZufelt_1-1713989829838.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/102070iC4ABD203CA615C30/image-size/large?v=v2&amp;amp;px=999" role="button" title="RhettZufelt_1-1713989829838.png" alt="RhettZufelt_1-1713989829838.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The space in the single quotes is the delimiter (single space).&amp;nbsp; If any of the val variables have a value, it will be concatenated, but, if Null, will just be ignored without error.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 20:17:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1414978#M82342</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-04-24T20:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to concatenate strings in millions of records ignoring nulls and spaces</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1415015#M82344</link>
      <description>&lt;P&gt;A Python if statement will be far from the slowest part of this process.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 21:07:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1415015#M82344</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-04-24T21:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to concatenate strings in millions of records ignoring nulls and spaces</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1415143#M82353</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;v = ['a', 'c', 'b', 'd', None]

v*2  # --- just to show you can expand lists
['a', 'c', 'b', 'd', None, 'a', 'c', 'b', 'd', None]

v0 = v*1000000  # lets make one with 5 million values

# ---- As Joshua says, it isn't slow, and there is an `if` statement in the # 
       list comprehension

%timeit ' '.join([x for x in v0 if x is not None ])
217 ms ± 31.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

# ---- What about filter using the first 4 values agains `None`

' '.join(filter(None, v[:4]))
'a c b d'

# ---- no slouch either, and largely insignificant

%timeit ' '.join(filter(None, v0))
170 ms ± 8.33 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;slow coding night &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 02:30:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/most-efficient-way-to-concatenate-strings-in/m-p/1415143#M82353</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-04-25T02:30:23Z</dc:date>
    </item>
  </channel>
</rss>

