<?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 A phyton script to Overwrite a feature layer base on a Pandas DataFrame in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201723#M65279</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I use a python script in Jupyter to get data from an external WebApp through its API, convert it to a pandas DataFrame, and publish it as a feature collection on AGOL . below is a part of the code where data (df_data) is imported as a feature collection and then gets published&amp;nbsp;&lt;/SPAN&gt;on AGOL.&lt;/P&gt;&lt;P&gt;df_data_fc = gis.content.import_data(df_data)&lt;/P&gt;&lt;P&gt;#Build a python dictionary from feature collection properties&lt;/P&gt;&lt;P&gt;df_data_fc_dict = dict(df_data_fc.properties)&lt;BR /&gt;df_data_json = json.dumps({"featureCollection": {"layers": [df_data_fc_dict]}})&lt;/P&gt;&lt;P&gt;#Use the dictionary in a list as the layers property of a json featureCollection to add the item to the portal&lt;/P&gt;&lt;P&gt;data_item_properties = {'title': ' Incidents Map',&lt;BR /&gt;'description':'Example demonstrating the integration between GIS and 3rd party portal ',&lt;BR /&gt;'tags': ' PCDS',&lt;BR /&gt;'text':df_data_json,&lt;BR /&gt;'type':'Feature Collection'}&lt;BR /&gt;data_item = gis.content.add(data_item_properties)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;At the moment I need to come up with a python script to overwrite the published feature layer daily instead of publishing a new layer through each update.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have done some research to find the related code but unfortunately,&amp;nbsp;there are no similar situations where someone wants to overwrite a layer with a pandas data frame.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any python scrip to use a pandas data frame in order to overwrite the above-published layer?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Aug 2022 02:21:40 GMT</pubDate>
    <dc:creator>Admin_D</dc:creator>
    <dc:date>2022-08-11T02:21:40Z</dc:date>
    <item>
      <title>A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201723#M65279</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I use a python script in Jupyter to get data from an external WebApp through its API, convert it to a pandas DataFrame, and publish it as a feature collection on AGOL . below is a part of the code where data (df_data) is imported as a feature collection and then gets published&amp;nbsp;&lt;/SPAN&gt;on AGOL.&lt;/P&gt;&lt;P&gt;df_data_fc = gis.content.import_data(df_data)&lt;/P&gt;&lt;P&gt;#Build a python dictionary from feature collection properties&lt;/P&gt;&lt;P&gt;df_data_fc_dict = dict(df_data_fc.properties)&lt;BR /&gt;df_data_json = json.dumps({"featureCollection": {"layers": [df_data_fc_dict]}})&lt;/P&gt;&lt;P&gt;#Use the dictionary in a list as the layers property of a json featureCollection to add the item to the portal&lt;/P&gt;&lt;P&gt;data_item_properties = {'title': ' Incidents Map',&lt;BR /&gt;'description':'Example demonstrating the integration between GIS and 3rd party portal ',&lt;BR /&gt;'tags': ' PCDS',&lt;BR /&gt;'text':df_data_json,&lt;BR /&gt;'type':'Feature Collection'}&lt;BR /&gt;data_item = gis.content.add(data_item_properties)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;At the moment I need to come up with a python script to overwrite the published feature layer daily instead of publishing a new layer through each update.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have done some research to find the related code but unfortunately,&amp;nbsp;there are no similar situations where someone wants to overwrite a layer with a pandas data frame.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any python scrip to use a pandas data frame in order to overwrite the above-published layer?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 02:21:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201723#M65279</guid>
      <dc:creator>Admin_D</dc:creator>
      <dc:date>2022-08-11T02:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201741#M65282</link>
      <description>&lt;P&gt;Wonder if you can use the overwrite method of &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html#arcgis.features.managers.FeatureLayerCollectionManager.overwrite" target="_blank" rel="noopener"&gt;FeatureLayerCollectionManager&lt;/A&gt;?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.features import FeatureLayerCollection
your_pandas_layer = FeatureLayerCollection.fromitem(old_item)

your_pandas_layer.manager.overwrite(data_item_properties)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 03:19:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201741#M65282</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-08-11T03:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201745#M65283</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks for the suggestions. I used the below code before but I got this error:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;TypeError&lt;/SPAN&gt;: item must be a type of service, not Feature Collection&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;from arcgis.features import FeatureLayerCollection&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;newfeaturecollection = FeatureLayerCollection.fromitem(&lt;STRONG&gt;data_item&lt;/STRONG&gt;)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 04:15:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201745#M65283</guid>
      <dc:creator>Admin_D</dc:creator>
      <dc:date>2022-08-11T04:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201758#M65284</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;Hi&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;I published the feature layer first as a feature service and then used the overwrite method to avoid the above error but I faced another error&amp;nbsp; at the last line of the script as below:&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;: Error while analyzing Feature Collection, Feature Collection JSON doesn't have 'layers'
(Error Code: 406)&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;Here is the lest version of the script. Any idea about this error?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;df_data_fc = gis.content.import_data(df_data)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;#Build a python dictionary from feature collection properties&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;df_data_fc_dict = dict(df_data_fc.properties)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;df_data_json = json.dumps({"featureCollection": {"layers": [df_data_fc_dict]}})&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;#Use the dictionary in a list as the layers property of a json featureCollection to add the item to the portal&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;data_item_properties = {'title': ' Incidents Map',&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;'description':'Example demonstrating the integration between GIS and 3rd party portal ',&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;'tags': ' PCDS',&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;'text':df_data_json,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;'type':'Feature Collection'}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;from arcgis.features import FeatureLayerCollection&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;published_layer = gis.content.get('0b0bf5083fea423daa99472937749b4d')&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;newfeaturecollection = FeatureLayerCollection.fromitem(published_layer)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;newfeaturecollection.manager.overwrite(data_item_properties)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 06:21:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201758#M65284</guid>
      <dc:creator>Admin_D</dc:creator>
      <dc:date>2022-08-11T06:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201822#M65286</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Looks like the data parameter for the overwrite method is expecting a file path and not a variable holding the json. &amp;nbsp;Try writing the json.dumps() to a temp file and use that path as the input. Since it keeps all the metadata the same, maybe the definition isn’t needed?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 11:21:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1201822#M65286</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-08-11T11:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1202288#M65292</link>
      <description>&lt;P&gt;I used both a csv file and a json file to in the overwrite method in the below script:&lt;/P&gt;&lt;P&gt;csvfilepath = r'C:\Users\***\TelematticaIncidents.csv'&lt;BR /&gt;jsonfilepath = r'C:\Users\***\data.json'&lt;/P&gt;&lt;P&gt;from arcgis.features import FeatureLayerCollection&lt;BR /&gt;#get the hosted feature layer&lt;BR /&gt;dataitem = gis.content.get('eba42b0e69374cf098ce55bf1cd2d4a7')&lt;BR /&gt;newflayercol = FeatureLayerCollection.fromitem(dataitem)&lt;BR /&gt;newflayercol.manager.overwrite(csvfilepath)&lt;BR /&gt;#newflayercol.manager.overwrite(jsonfilepath)&lt;/P&gt;&lt;P&gt;But I got the below error:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;: Error while analyzing Feature Collection, Feature Collection JSON is empty
(Error Code: 406)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I also attached the csv file and the json file to this reply.&lt;/P&gt;&lt;P&gt;Is there any thought on this?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 06:50:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1202288#M65292</guid>
      <dc:creator>Admin_D</dc:creator>
      <dc:date>2022-08-12T06:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1202344#M65294</link>
      <description>&lt;P&gt;Every hour, I have a script that exports a pandas DataFrame to a CSV, and &lt;EM&gt;then&lt;/EM&gt; uses that to overwrite a hosted table in my account.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#This gets the hosted table in AGOL
table = gis.content.get('item number here')  

#from arcgis.features import FeatureLayerCollection
projects_collection = FeatureLayerCollection.fromitem(table)

#pandas exported to CSV
df4.to_csv(newCSV4, date_format='%m/%d/%Y')  

#overwrite old table with new csv data
projects_collection.manager.overwrite(newCSV4)  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;I do this as it keeps the CSV created as a backup.&amp;nbsp; Every time the script is run, the previous CSV is renamed and stored and then the new CSV takes on the original table name.&amp;nbsp; I only ever keep the current table and the old csv.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 12:44:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1202344#M65294</guid>
      <dc:creator>Kara_Shindle</dc:creator>
      <dc:date>2022-08-12T12:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1202369#M65295</link>
      <description>&lt;P&gt;Not sure if it has anything to do with it, but in the data.json file, the text key has a python dictionary and not true json. Do they want GeoJSON, EsriJSON, or another standard? Seems that any standard that is tried results in an error...&amp;nbsp;&lt;/P&gt;&lt;P&gt;I saw that there is an old solution from 2018 that does this text: dictionary too, but I keep getting the 406 error or other failing stuff so maybe they updated that process and it no longer works that way.&lt;/P&gt;&lt;P&gt;The csv upload method seems more stable if you could dump the df into a csv instead of the JSON.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 13:57:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1202369#M65295</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-08-12T13:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: A phyton script to Overwrite a feature layer base on a Pandas DataFrame</title>
      <link>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1202709#M65307</link>
      <description>&lt;P&gt;&amp;nbsp;This time I published the primary file in a csv format manually instead of publishing it as a json file from a dictionary. The scrip works without any problem.&lt;/P&gt;&lt;P&gt;Thanks Jeffk&lt;/P&gt;</description>
      <pubDate>Sun, 14 Aug 2022 23:19:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/a-phyton-script-to-overwrite-a-feature-layer-base/m-p/1202709#M65307</guid>
      <dc:creator>Admin_D</dc:creator>
      <dc:date>2022-08-14T23:19:48Z</dc:date>
    </item>
  </channel>
</rss>

