Let us overwrite the feature layer using the new csv file we just created. To overwrite, we will use the overwrite() method.
from arcgis.features import FeatureLayerCollection
cities_flayer_collection = FeatureLayerCollection.fromitem(cities_item)
#call the overwrite() method which can be accessed using the manager property
cities_flayer_collection.manager.overwrite(os.path.join('data', 'updating_gis_content',
'updated_capitals_csv', 'capitals_1.csv'))
I export dataframe directly to a CSV that overwrites the file on AGOL every hour. I couldn't get the dataframe to work and haven't had the time to suss out why but here is my code:
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
gis = GIS('<AGOL ORG URL>', usernameAGOL, passy)
# #### 3.1.2 Update Parcel Action List
searchResult = gis.content.search(query="title:Parcel Action List")
pal = searchResult[1]
palTable = gis.content.get('<Insert item number here>') #This gets the hosted table in AGOL
pal_collection = FeatureLayerCollection.fromitem(palTable)
pal_collection.manager.overwrite(newCSV)
where newCSV is the CSV I exported from my pandas frame and is stored in a folder every hour. Every hour, it finds the CSV, renames it to "CSV_OLD" in case something goes wrong, and then recreates a new CSV from the data with the same name.
Edited to include gis variable in python
I'm not versed enough to be able to get the token stuff working yet - so I explicitly state the username & password in this script, although you should probably at least create a secrets file if you know how
Thank you