<?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: Use feature layer alias for column names in dataframe in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/use-feature-layer-alias-for-column-names-in/m-p/1063123#M6146</link>
    <description>&lt;P&gt;Late answer, but yes! Totally possible, though requiring a couple of extra steps.&lt;/P&gt;&lt;P&gt;We'll use pandas' &lt;A href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename.html" target="_self"&gt;&lt;STRONG&gt;rename&lt;/STRONG&gt; method&lt;/A&gt; on the dataframe, which takes the &lt;STRONG&gt;columns&lt;/STRONG&gt; parameter of a dict in the format&lt;/P&gt;&lt;PRE&gt;{&lt;BR /&gt;  'old_column_name':'new_column_name',&lt;BR /&gt;  'another_old':'another_new'&lt;BR /&gt;  ...&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;First, we need to construct that dict. The featurelayer object should have a &lt;STRONG&gt;properties&lt;/STRONG&gt; property which returns the JSON definition. Within that definitions is the &lt;STRONG&gt;fields &lt;/STRONG&gt;list. Each item in the list is its own dict with values for "name" and "alias". We'll iterate over this and populate values in an empty dict, &lt;STRONG&gt;rep_dict&lt;/STRONG&gt;, then use that in the &lt;STRONG&gt;rename&lt;/STRONG&gt; method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis import GIS
from arcgis import GeoAccessor

# get layer, convert to dataframe
fl = gis.content.get('your_layer_itemid').layers[0]
sdf = GeoAccessor.from_layer(fl)

# construct rep_dict
rep_dict = {}

for f in fl.properties['fields']:
    rep_dict[f['name']] = f['alias']

# rename fields
sdf.rename(columns=rep_dict, inplace=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And that should do it!&lt;/P&gt;</description>
    <pubDate>Sat, 29 May 2021 14:08:43 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2021-05-29T14:08:43Z</dc:date>
    <item>
      <title>Use feature layer alias for column names in dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/use-feature-layer-alias-for-column-names-in/m-p/1057510#M6055</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am&amp;nbsp; converting a featurelayer to pandas dataframe in ArcGIS online notebooks, but I want the column names come from the layer's field aliases not the field names.&amp;nbsp; Using&amp;nbsp;DataFrame.spatial.from_layer() has no option for this.&amp;nbsp; Does anyone know another way this can be achieved?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 07:39:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/use-feature-layer-alias-for-column-names-in/m-p/1057510#M6055</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-05-13T07:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use feature layer alias for column names in dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/use-feature-layer-alias-for-column-names-in/m-p/1063123#M6146</link>
      <description>&lt;P&gt;Late answer, but yes! Totally possible, though requiring a couple of extra steps.&lt;/P&gt;&lt;P&gt;We'll use pandas' &lt;A href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename.html" target="_self"&gt;&lt;STRONG&gt;rename&lt;/STRONG&gt; method&lt;/A&gt; on the dataframe, which takes the &lt;STRONG&gt;columns&lt;/STRONG&gt; parameter of a dict in the format&lt;/P&gt;&lt;PRE&gt;{&lt;BR /&gt;  'old_column_name':'new_column_name',&lt;BR /&gt;  'another_old':'another_new'&lt;BR /&gt;  ...&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;First, we need to construct that dict. The featurelayer object should have a &lt;STRONG&gt;properties&lt;/STRONG&gt; property which returns the JSON definition. Within that definitions is the &lt;STRONG&gt;fields &lt;/STRONG&gt;list. Each item in the list is its own dict with values for "name" and "alias". We'll iterate over this and populate values in an empty dict, &lt;STRONG&gt;rep_dict&lt;/STRONG&gt;, then use that in the &lt;STRONG&gt;rename&lt;/STRONG&gt; method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis import GIS
from arcgis import GeoAccessor

# get layer, convert to dataframe
fl = gis.content.get('your_layer_itemid').layers[0]
sdf = GeoAccessor.from_layer(fl)

# construct rep_dict
rep_dict = {}

for f in fl.properties['fields']:
    rep_dict[f['name']] = f['alias']

# rename fields
sdf.rename(columns=rep_dict, inplace=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And that should do it!&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 14:08:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/use-feature-layer-alias-for-column-names-in/m-p/1063123#M6146</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-05-29T14:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Use feature layer alias for column names in dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/use-feature-layer-alias-for-column-names-in/m-p/1063181#M6148</link>
      <description>&lt;P&gt;Worked perfect! Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 00:24:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/use-feature-layer-alias-for-column-names-in/m-p/1063181#M6148</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-05-31T00:24:39Z</dc:date>
    </item>
  </channel>
</rss>

