<?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 iterate hosted (AGOL) table attributes in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225330#M7932</link>
    <description>&lt;P&gt;Edit: this is a hosted Notebook on our AGOL org&lt;/P&gt;&lt;P&gt;I can't believe I cannot see any examples in the docs on simply accessing attributes of a hosted AGOL table/service, prbly just missing the obvious here.&amp;nbsp; I can get to all attributes of "features" but I'm unsure how to go about getting a specific attribute for each feature but had to actually apply a query to get the list object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import time, os
from datetime import datetime, timedelta

from arcgis.gis import GIS
gis = GIS("home")
from arcgis.features import FeatureLayer
from arcgis.features import FeatureLayerCollection

t = time.localtime()
last_date_time = datetime.utcnow() - timedelta(days = 18)
timestamp = last_date_time.strftime("%Y-%m-%d %H:%M:%S")
#timestamp = '2022-10-02 15:00:00 PM'

sunsetTabId = '5cf39cfa77694131821ec89cc1bf0150'
sunsetTabItem = gis.content.get(sunsetTabId)

fields=['itemIdToProcess','daysToKeep']

for tab in sunsetTabItem.tables:
    tabSet = tab.query(where='OBJECTID&amp;gt;0')
    print (tab.properties.name)
    for row in tabSet.features:
        print (row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This iterates over the "tabSet.features" object and I can print each row but unsure how to get at each "itemId" value each iteration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;{"attributes": {"OBJECTID": 1, "itemId": "416c10d63b78464798abc3c10e70c71b", "daysToKeep": 10}}
{"attributes": {"OBJECTID": 2, "itemId": "105f5c3e534744da9df8a0d8953fffc2", "daysToKeep": 5}}
{"attributes": {"OBJECTID": 3, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 4, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 5, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 6, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 7, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 8, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 9, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 10, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 11, "itemId": null, "daysToKeep": 1}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I cannot get "itemId"?&lt;/P&gt;&lt;P&gt;I've tried several combinations of things like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for row in qResult.features:
     print (row.attributes.itemId)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But gives&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;AttributeError&lt;/SPAN&gt;: 'dict' object has no attribute 'itemId'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Oct 2022 18:55:48 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2022-10-25T18:55:48Z</dc:date>
    <item>
      <title>iterate hosted (AGOL) table attributes</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225330#M7932</link>
      <description>&lt;P&gt;Edit: this is a hosted Notebook on our AGOL org&lt;/P&gt;&lt;P&gt;I can't believe I cannot see any examples in the docs on simply accessing attributes of a hosted AGOL table/service, prbly just missing the obvious here.&amp;nbsp; I can get to all attributes of "features" but I'm unsure how to go about getting a specific attribute for each feature but had to actually apply a query to get the list object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import time, os
from datetime import datetime, timedelta

from arcgis.gis import GIS
gis = GIS("home")
from arcgis.features import FeatureLayer
from arcgis.features import FeatureLayerCollection

t = time.localtime()
last_date_time = datetime.utcnow() - timedelta(days = 18)
timestamp = last_date_time.strftime("%Y-%m-%d %H:%M:%S")
#timestamp = '2022-10-02 15:00:00 PM'

sunsetTabId = '5cf39cfa77694131821ec89cc1bf0150'
sunsetTabItem = gis.content.get(sunsetTabId)

fields=['itemIdToProcess','daysToKeep']

for tab in sunsetTabItem.tables:
    tabSet = tab.query(where='OBJECTID&amp;gt;0')
    print (tab.properties.name)
    for row in tabSet.features:
        print (row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This iterates over the "tabSet.features" object and I can print each row but unsure how to get at each "itemId" value each iteration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;{"attributes": {"OBJECTID": 1, "itemId": "416c10d63b78464798abc3c10e70c71b", "daysToKeep": 10}}
{"attributes": {"OBJECTID": 2, "itemId": "105f5c3e534744da9df8a0d8953fffc2", "daysToKeep": 5}}
{"attributes": {"OBJECTID": 3, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 4, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 5, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 6, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 7, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 8, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 9, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 10, "itemId": null, "daysToKeep": 1}}
{"attributes": {"OBJECTID": 11, "itemId": null, "daysToKeep": 1}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I cannot get "itemId"?&lt;/P&gt;&lt;P&gt;I've tried several combinations of things like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for row in qResult.features:
     print (row.attributes.itemId)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But gives&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;AttributeError&lt;/SPAN&gt;: 'dict' object has no attribute 'itemId'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 18:55:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225330#M7932</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-10-25T18:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: iterate hosted (AGOL) table attributes</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225347#M7933</link>
      <description>&lt;P&gt;row['itemId']&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 19:14:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225347#M7933</guid>
      <dc:creator>DavidAnderson_1701</dc:creator>
      <dc:date>2022-10-25T19:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: iterate hosted (AGOL) table attributes</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225351#M7934</link>
      <description>&lt;PRE&gt;&lt;SPAN class=""&gt;TypeError&lt;/SPAN&gt;                                 Traceback (most recent call last)
Input &lt;SPAN class=""&gt;In [143]&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;&amp;lt;cell line: 20&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;()&lt;/SPAN&gt;
&lt;SPAN class=""&gt;     21&lt;/SPAN&gt; tabSet &lt;SPAN&gt;=&lt;/SPAN&gt; tab&lt;SPAN&gt;.&lt;/SPAN&gt;query(where&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;1=1&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;)    
&lt;SPAN class=""&gt;     22&lt;/SPAN&gt; &lt;SPAN class=""&gt;for&lt;/SPAN&gt; row &lt;SPAN class=""&gt;in&lt;/SPAN&gt; tabSet:        
&lt;SPAN class=""&gt;---&amp;gt; 23&lt;/SPAN&gt;     &lt;SPAN&gt;print&lt;/SPAN&gt; (&lt;SPAN class=""&gt;row&lt;/SPAN&gt;&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;'&lt;/SPAN&gt;&lt;SPAN class=""&gt;itemId&lt;/SPAN&gt;&lt;SPAN class=""&gt;'&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;)

&lt;SPAN class=""&gt;TypeError&lt;/SPAN&gt;: 'Feature' object is not subscriptable&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Oct 2022 19:16:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225351#M7934</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-10-25T19:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: iterate hosted (AGOL) table attributes</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225365#M7935</link>
      <description>&lt;P&gt;I guess I have to use the pandas dataframe object of the tabSet?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for tab in sunsetTabItem.tables:    
    tabSet = tab.query(where='1=1',as_df=True)       
    for index, row in tabSet.iterrows():
        print (row.itemId + "|" + str(row.daysToKeep))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Produces:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;416c10d63b78464798abc3c10e70c71b|10
105f5c3e534744da9df8a0d8953fffc2|5
None|1
None|1
None|1
None|1
None|1
None|1
None|1
None|1
None|1&lt;/LI-CODE&gt;&lt;P&gt;I guess I was expecting the python API to provide access to values of columns specified (ie, ".itemId")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 19:35:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225365#M7935</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-10-25T19:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: iterate hosted (AGOL) table attributes</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225385#M7939</link>
      <description>&lt;P&gt;The feature isn't subscriptable, but its &lt;STRONG&gt;attributes&lt;/STRONG&gt; property (a dict) &lt;EM&gt;is&lt;/EM&gt;.&lt;/P&gt;&lt;PRE&gt;for row in tabSet:&lt;BR /&gt;    print(row.attributes['itemId'])&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Oct 2022 19:54:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225385#M7939</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-10-25T19:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: iterate hosted (AGOL) table attributes</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225408#M7941</link>
      <description>&lt;P&gt;That works.&amp;nbsp; Thanks -- I really was questioning if I had to actually iterate the dataframe!&amp;nbsp; This will def simplify it a level or two.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 20:28:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/iterate-hosted-agol-table-attributes/m-p/1225408#M7941</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-10-25T20:28:32Z</dc:date>
    </item>
  </channel>
</rss>

