python to update a field in a feature layer based on records in csv file

2171
10
02-28-2022 11:07 AM
Nahomdinka
New Contributor II

Hello:

I am a little bit new to coding. I would like to update an existing feature layer in AGOL using an open-source python library. Only one field (let us say field1) needs to be updated in the feature layer based on source data in csv. The feature layer and the .csv file have a common field to join them. Field_ID in the feature layer and CSV_ID in CSV file are used to join or map the source and the target. I do not think it matters but Field_ID is not unique. I am looking for a python code to automate the process of updating features in the feature layer using data from csv. I can not overwrite the feature layer because there are records or fields in the feature layer that are not in the csv. 

Below is what I have...

import pandas as pd

import os

from arcgis.gis import GIS

from arcgis import features

from arcgis.features import SpatialDataFrame

from arcgis.mapping import WebMap

import arcpy

from arcgis.features import FeatureLayerCollection

csvFile = pd.read_csv("csvfile.csv")

portal ="htttps://xyz.maps.arcgis.com/"

username  = "abc"

pw = "pword"

gis = GIS(portal, username, pw)

Feature_layerID  = gis.content.get("123456789")

#replace the records in the "field1" of the feature layer based on the data in csv file, using the two common IDs in the feature layer and the csv file (Field_ID in the feature layer and CSV_ID in CSV file are used to join or map the source and the target). 

 

0 Kudos
10 Replies
Robert_LeClair
Esri Notable Contributor

@JeffBigos - can you assist the Python question here?  The customer - Nohomdinka - requested my assistance but I do not program in Python so am out of my wheelhouse here.  Thx!

0 Kudos