<?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: Populating attribute table with IF statement in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100731#M45862</link>
    <description>&lt;P&gt;formatting your code will help spot syntax issues&amp;nbsp;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Are the values 1-10 possibly integers and need the single quotes removed:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if x == 1:
  return 'ForestCover'&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 22 Sep 2021 10:34:54 GMT</pubDate>
    <dc:creator>DavidPike</dc:creator>
    <dc:date>2021-09-22T10:34:54Z</dc:date>
    <item>
      <title>Populating attribute table with IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100723#M45860</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies for what is probably a very simple question with an easy solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to populate a field of my attribute table using an if statement. Specifically, I have a field with vegetation types (1 - 10) but I want a new field where each of those values is assigned a name (i.e. forest cover). So If my cell value is 1, I want the new field to be assigned a value 'forest cover'. I've tried the following piece of code similar to previous answers but it is not working. Can anyone help me with a solution?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;def customReplace(x):&lt;BR /&gt;if x=='1':&lt;BR /&gt;return 'ForestCover'&lt;BR /&gt;elif x=='2':&lt;BR /&gt;return 'ShrubCover'&lt;BR /&gt;elif x=='3':&lt;BR /&gt;return 'Grassland'&lt;BR /&gt;elif x=='4':&lt;BR /&gt;return 'Cropland'&lt;BR /&gt;elif x=='5':&lt;BR /&gt;return 'Floodland'&lt;BR /&gt;elif x=='6':&lt;BR /&gt;return 'SparseVeg'&lt;BR /&gt;elif VegType =='7':&lt;BR /&gt;return 'Bare'&lt;BR /&gt;elif x=='8':&lt;BR /&gt;return 'Built'&lt;BR /&gt;elif x=='10':&lt;BR /&gt;return 'Water'&lt;BR /&gt;else:&lt;BR /&gt;return "Not Found"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 09:50:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100723#M45860</guid>
      <dc:creator>EmmaE1</dc:creator>
      <dc:date>2021-09-22T09:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Populating attribute table with IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100731#M45862</link>
      <description>&lt;P&gt;formatting your code will help spot syntax issues&amp;nbsp;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Are the values 1-10 possibly integers and need the single quotes removed:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if x == 1:
  return 'ForestCover'&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 10:34:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100731#M45862</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-09-22T10:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Populating attribute table with IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100744#M45864</link>
      <description>&lt;P&gt;Alternately you can create a domain out of the vegetation types and assign that domain to the attribute with the vegetation&amp;nbsp; types.&lt;/P&gt;&lt;P&gt;However, as you only have a very few choices why not just do a query and update the new attribute manually. It would take less time than it does to write to code&lt;/P&gt;&lt;P&gt;Or if you switch to Arcade the code would look like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;iif($feature.[attribute] = 1, 'Forest Cover', iif($feature.[attribute] = 2 , 'Shrub Cover', etc etc...))&lt;/P&gt;&lt;P&gt;Just continue the second value until you get to 10 then make the final value Not Found instead of a new iff statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 11:42:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100744#M45864</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2021-09-22T11:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Populating attribute table with IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100745#M45865</link>
      <description>&lt;P&gt;Or create a look up table as a .csv or .txt file.&amp;nbsp; Bring it into your project, to a join and populate the text field.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 11:43:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100745#M45865</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2021-09-22T11:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Populating attribute table with IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100758#M45867</link>
      <description>&lt;P&gt;Just as a side note, nesting 10 IIFs is bound to get complicated with the closing parantheses. It's much easier to do&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var att = $feature.Attribute
return When(att==1, "ForestCover", att==2, "ShrubCover", att=3, "Grassland", "Not Found")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 12:26:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100758#M45867</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-09-22T12:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Populating attribute table with IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100769#M45869</link>
      <description>&lt;P&gt;Agreed, but on a different side note.&amp;nbsp; Why bother to create a line of code to to the calculation for only 10 values?&lt;/P&gt;&lt;P&gt;Set up the Query in Pro starting at 1 and manually field calculate the values. For that few values it would take longer to write the code.&amp;nbsp; However, 10 iffs = 10 opening parenthesis which would equal 10 closing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 12:54:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100769#M45869</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2021-09-22T12:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Populating attribute table with IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100782#M45871</link>
      <description>&lt;P&gt;Sure, doing it manually is very feasible, here. Either with a query or with Select By Attribute.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 13:24:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100782#M45871</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-09-22T13:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Populating attribute table with IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100822#M45877</link>
      <description>&lt;P&gt;I like a good lookup table myself. If you don't have a text file handy for this, you can also just establish a dict of values for your lookup, thus bypassing external files, joins, and nested conditionals altogether.&lt;/P&gt;&lt;P&gt;PS, the post has an &lt;STRONG&gt;arcade&lt;/STRONG&gt; tag on it, but the presence of "elif" suggests this is Python. &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/522602"&gt;@EmmaE1&lt;/a&gt; could you clarify your coding language?&lt;/P&gt;&lt;P&gt;In Python:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def customReplace(x):

    values = {
        '1': 'ForestCover',
        '2': 'ShrubCover',
        '3': 'Grassland',
        '4': 'Cropland',
        '5': 'Floodland',
        '6': 'SparceVeg',
        '7': 'Bare',
        '8': 'Built',
        '10': 'Water'
    }

    return values[x]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Arcade:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var a = $feature.FLOORCOUNT

var values = {
    '1': 'ForestCover',
    '2': 'ShrubCover',
    '3': 'Grassland',
    '4': 'Cropland',
    '5': 'Floodland',
    '6': 'SparceVeg',
    '7': 'Bare',
    '8': 'Built',
    '10': 'Water'
}

return values[a]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 14:19:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/populating-attribute-table-with-if-statement/m-p/1100822#M45877</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-09-22T14:19:45Z</dc:date>
    </item>
  </channel>
</rss>

