<?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 Updating Fields in a Feature Layer Using a Dataframe in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1033176#M5658</link>
    <description>&lt;P&gt;I am trying to update fields in a feature layer using a dataframe that I read in via a csv file in order to update a map on an annual basis. I am not sure how to use the edit_features command to update the fields based on a join of a unique key between the dataframe and the feature layer.&lt;/P&gt;&lt;P&gt;This is what I have so far. I am trying to update the fields rpl_theme1 through rpl_themes but retain the geometry. So I am hoping there is a way to use some code to look for the unique key BOROUGH_TRACT in the feature layer and update the fields using the dataframe.&lt;/P&gt;&lt;P&gt;The feature layer has the following data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MackWood_0-1614895641040.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7572iC27F15501C90A409/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MackWood_0-1614895641040.png" alt="MackWood_0-1614895641040.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And the dataframe the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MackWood_1-1614895667303.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7573i5B6D028A048C7CEE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MackWood_1-1614895667303.png" alt="MackWood_1-1614895667303.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
gis = GIS("home")

#set file paths
overall_rank = '/arcgis/home/overall_rank_2019.csv'
#overall_flags = '/arcgis/home/overall_flags_2019.csv'
#theme1_rank = '/arcgis/home/theme1_rank_2019.csv'
#theme1_flags = '/arcgis/home/theme1_flags_2019.csv'
#theme2_rank = '/arcgis/home/theme2_rank_2019.csv'
#theme2_flags = '/arcgis/home/theme2_flags_2019.csv'
#theme3_rank = '/arcgis/home/theme3_rank_2019.csv'
#theme3_flags = '/arcgis/home/theme3_flags_2019.csv'
#theme4_rank = '/arcgis/home/theme4_rank_2019.csv'
#theme4_flags = '/arcgis/home/theme4_flags_2019.csv'

#import packages
import pandas
import arcgis
import numpy as np
import arcpy

#read csv files with borough and tract as strings to retain leading 0s
overall_rank_df = pandas.read_csv(overall_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#overall_flags_df =  pandas.read_csv(overall_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme1_rank_df = pandas.read_csv(theme1_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme1_flags_df = pandas.read_csv(theme1_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme2_rank_df = pandas.read_csv(theme2_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme2_flags_df = pandas.read_csv(theme2_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme3_rank_df = pandas.read_csv(theme3_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme3_flags_df = pandas.read_csv(theme3_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme4_rank_df = pandas.read_csv(theme4_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme4_flags_df = pandas.read_csv(theme4_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})

overall_rank_df["BOROUGH_TRACT"]=overall_rank_df["BOROUGH"]+overall_rank_df["tract"]

HEI_Features_itemID = "fa044b611f7d4f77a57d4c0e42edbe2e"
HEI_Features_Item = gis.content.get(HEI_Features_itemID)

overall_rank_flayer = HEI_Features_Item.layers[4]
overall_rank_fset = overall_rank_flayer.query() #querying without any conditions returns all the features
overall_rank_flayer_rows = overall_rank_fset.sdf

overall_rank_flayer_rows

overall_rank_flayer.properties.capabilities

overall_rank_df&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 22:10:42 GMT</pubDate>
    <dc:creator>MackWood</dc:creator>
    <dc:date>2021-03-04T22:10:42Z</dc:date>
    <item>
      <title>Updating Fields in a Feature Layer Using a Dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1033176#M5658</link>
      <description>&lt;P&gt;I am trying to update fields in a feature layer using a dataframe that I read in via a csv file in order to update a map on an annual basis. I am not sure how to use the edit_features command to update the fields based on a join of a unique key between the dataframe and the feature layer.&lt;/P&gt;&lt;P&gt;This is what I have so far. I am trying to update the fields rpl_theme1 through rpl_themes but retain the geometry. So I am hoping there is a way to use some code to look for the unique key BOROUGH_TRACT in the feature layer and update the fields using the dataframe.&lt;/P&gt;&lt;P&gt;The feature layer has the following data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MackWood_0-1614895641040.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7572iC27F15501C90A409/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MackWood_0-1614895641040.png" alt="MackWood_0-1614895641040.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And the dataframe the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MackWood_1-1614895667303.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7573i5B6D028A048C7CEE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MackWood_1-1614895667303.png" alt="MackWood_1-1614895667303.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
gis = GIS("home")

#set file paths
overall_rank = '/arcgis/home/overall_rank_2019.csv'
#overall_flags = '/arcgis/home/overall_flags_2019.csv'
#theme1_rank = '/arcgis/home/theme1_rank_2019.csv'
#theme1_flags = '/arcgis/home/theme1_flags_2019.csv'
#theme2_rank = '/arcgis/home/theme2_rank_2019.csv'
#theme2_flags = '/arcgis/home/theme2_flags_2019.csv'
#theme3_rank = '/arcgis/home/theme3_rank_2019.csv'
#theme3_flags = '/arcgis/home/theme3_flags_2019.csv'
#theme4_rank = '/arcgis/home/theme4_rank_2019.csv'
#theme4_flags = '/arcgis/home/theme4_flags_2019.csv'

#import packages
import pandas
import arcgis
import numpy as np
import arcpy

#read csv files with borough and tract as strings to retain leading 0s
overall_rank_df = pandas.read_csv(overall_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#overall_flags_df =  pandas.read_csv(overall_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme1_rank_df = pandas.read_csv(theme1_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme1_flags_df = pandas.read_csv(theme1_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme2_rank_df = pandas.read_csv(theme2_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme2_flags_df = pandas.read_csv(theme2_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme3_rank_df = pandas.read_csv(theme3_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme3_flags_df = pandas.read_csv(theme3_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme4_rank_df = pandas.read_csv(theme4_rank, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})
#theme4_flags_df = pandas.read_csv(theme4_flags, converters={'BOROUGH': lambda x: str(x), 'tract': lambda x: str(x)})

overall_rank_df["BOROUGH_TRACT"]=overall_rank_df["BOROUGH"]+overall_rank_df["tract"]

HEI_Features_itemID = "fa044b611f7d4f77a57d4c0e42edbe2e"
HEI_Features_Item = gis.content.get(HEI_Features_itemID)

overall_rank_flayer = HEI_Features_Item.layers[4]
overall_rank_fset = overall_rank_flayer.query() #querying without any conditions returns all the features
overall_rank_flayer_rows = overall_rank_fset.sdf

overall_rank_flayer_rows

overall_rank_flayer.properties.capabilities

overall_rank_df&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 22:10:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1033176#M5658</guid>
      <dc:creator>MackWood</dc:creator>
      <dc:date>2021-03-04T22:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Updating Fields in a Feature Layer Using a Dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1034758#M5679</link>
      <description>&lt;P&gt;Hi MackWood my understanding is you want to update a feature layer's attribute table according to a dataframe. If this is the case, i think we can use the arcpy.da.UpdateCursor to archive this. It would be something like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;#import excel to dataFrame&lt;BR /&gt;df = pandas.read_excel(fileName,sheetName,header = None,parse_cols = [0])&lt;BR /&gt;df.columns=['rpl_theme']&lt;/P&gt;&lt;P&gt;fc = r"C:/your/path"&lt;BR /&gt;field = ['rpl_theme1']&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor(fc, field) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;if row[0] == rpl_theme:&lt;BR /&gt;row[0] =&amp;nbsp;rpl_theme1&lt;BR /&gt;cursor.updateRow(row)&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 00:02:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1034758#M5679</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-03-10T00:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Updating Fields in a Feature Layer Using a Dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1034777#M5680</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/375460"&gt;@MackWood&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;You can follow the link below from esri sample notebooks (&lt;STRONG&gt;Apply updates from the second spreadsheet&lt;/STRONG&gt;).&amp;nbsp;This provides a step by step guide from reading a csv file, a feature layer, joining them and finally updating the attribute fields based on your csv dataframe. You just need to skip the geometry updates.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/sample-notebooks/updating-features-in-a-feature-layer/" target="_blank"&gt;https://developers.arcgis.com/python/sample-notebooks/updating-features-in-a-feature-layer/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that helps.&lt;/P&gt;&lt;P&gt;Mehdi&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 01:42:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1034777#M5680</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2021-03-10T01:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Updating Fields in a Feature Layer Using a Dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1034796#M5681</link>
      <description>&lt;P&gt;I got the same thing.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 04:38:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-fields-in-a-feature-layer-using-a/m-p/1034796#M5681</guid>
      <dc:creator>JimmyWang</dc:creator>
      <dc:date>2021-03-10T04:38:44Z</dc:date>
    </item>
  </channel>
</rss>

