<?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 Read domain descriptions into spatially enabled dataframe in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1171010#M7370</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm reading hosted feature layers from AGOL into a spatially enabled dataframe.&lt;/P&gt;&lt;P&gt;The fields that have coded value domains on them pass through the code from the domain, not the description.&lt;/P&gt;&lt;P&gt;Is there any way to substitute the code with the description when creating the dataframe? I can't find anything about that in the documentation.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Hanlie&lt;/P&gt;</description>
    <pubDate>Thu, 05 May 2022 10:11:01 GMT</pubDate>
    <dc:creator>HanliePetoors</dc:creator>
    <dc:date>2022-05-05T10:11:01Z</dc:date>
    <item>
      <title>Read domain descriptions into spatially enabled dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1171010#M7370</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm reading hosted feature layers from AGOL into a spatially enabled dataframe.&lt;/P&gt;&lt;P&gt;The fields that have coded value domains on them pass through the code from the domain, not the description.&lt;/P&gt;&lt;P&gt;Is there any way to substitute the code with the description when creating the dataframe? I can't find anything about that in the documentation.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Hanlie&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 10:11:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1171010#M7370</guid>
      <dc:creator>HanliePetoors</dc:creator>
      <dc:date>2022-05-05T10:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Read domain descriptions into spatially enabled dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1171053#M7371</link>
      <description>&lt;P&gt;You can't sub in the descriptions initially, but a simple replacement is quite easy. I have a little function I use in scripts where I want the descriptions instead of the codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def domain_descriptions(df, service):
    """
    Takes a queried dataframe and its parent service and applies all fieldname aliases and domain names.
    Not especially useful for updating web layers, but *great* for when the queried dataframe will be exported to some other format.

        Parameters:
            df (DataFrame): A dataframe queried out of a hosted feature service or table.
            service (FeatureLayer or Table): A layer or table from a Feature Service.

        Returns:
            None, just modifies the input DataFrame.
    """
    aliases = {f'{i["name"]}':f'{i["alias"]}' for (i) in service.properties['fields']}
    domains = {i['name']:{str(j['code']):j['name'] for (j) in i['domain']['codedValues']} for (i) in service.properties["fields"] if 'domain' in i and i['domain'] is not None}

    for d in domains:
        if d in df.columns.to_list():
            df[d] = df[d].astype('str').replace(domains[d])

    df.rename(columns=aliases, inplace=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try it out! In practice, it might look like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl = gis.content.get('some-itemid').layers[0]

df = fl.query(as_df=True)

domain_descriptions(df, fl)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 May 2022 13:21:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1171053#M7371</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-05-05T13:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read domain descriptions into spatially enabled dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1171386#M7376</link>
      <description>&lt;P&gt;Thanks very much Josh, your script does exactly what I needed. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2022 07:54:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1171386#M7376</guid>
      <dc:creator>HanliePetoors</dc:creator>
      <dc:date>2022-05-06T07:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Read domain descriptions into spatially enabled dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1211973#M7741</link>
      <description>&lt;P&gt;This is excellent. I was coding something very similar.&amp;nbsp; Just adding to the thread... I also have range domains in my data so had to ignore these by just looking at the coded domains.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;coded_domains = {fld.name:{str(entry.code):entry.name for entry in fld.domain.codedValues} for fld in lyr.properties.fields if fld.domain and fld.domain.type == "codedValue"}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 13:31:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/read-domain-descriptions-into-spatially-enabled/m-p/1211973#M7741</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-09-13T13:31:58Z</dc:date>
    </item>
  </channel>
</rss>

