<?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 Re: How to update attribute table from a .csv and add new rows to apply geometry in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-update-attribute-table-from-a-csv-and-add/m-p/1241502#M63456</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# input parameters
fc = r"N:\...\db.gdb\TestPoints"  # path to the fc
csv = r"N:\...\testpoints.csv"  # path to csv
copy_fields = ["TextField", "IntegerField", "DoubleField"]  # list of the fields you want to copy. First field has to be a unique identifer


import arcpy
# read the csv, store its data in a dictionary
csv_dict = {row[0]: row for row in arcpy.da.SearchCursor(csv, copy_fields)}

# loop over the features with an UpdateCursor
with arcpy.da.UpdateCursor(fc, copy_fields) as cursor:
    for row in cursor:
        # get the csv data for that row
        key = row[0]
        try:
            new_row = csv_dict[key]
        except KeyError:  # row not found in csv
            print(f"Entry not found in csv: {copy_fields[0]} = {key}")
#            cursor.deleteRow()  # uncomment this to delete the feature
            continue
        # update the feature
        cursor.updateRow(new_row)
        del csv_dict[key]

# every feature that is left in the csv_dict is new
with arcpy.da.InsertCursor(fc, copy_fields) as cursor:
    for new_row in csv_dict.values():
        cursor.insertRow(new_row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Dec 2022 12:05:21 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-12-15T12:05:21Z</dc:date>
    <item>
      <title>How to update attribute table from a .csv and add new rows to apply geometry</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-update-attribute-table-from-a-csv-and-add/m-p/1241438#M63449</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a feature class that has numerous polygons with a bunch of attribute information. I also have a .csv file that contains the same info as the attribute table but is updated monthly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do two things: I want to update the values for the attribute table to reflect any changes that happened in the .csv (IE: change the "status" field from "active" to "expired).&amp;nbsp; I figure I could use arcpy's update cursor for this (I only have as much experience as the "Creating Python Scripts" course offered by esri).&lt;/P&gt;&lt;P&gt;Second, I want to add new any new rows that are in the .csv file but are not in the attribute table so that I can draw geometry for them. I guess I would need an insert cursor for this?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 02:18:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-update-attribute-table-from-a-csv-and-add/m-p/1241438#M63449</guid>
      <dc:creator>jgstaley</dc:creator>
      <dc:date>2022-12-15T02:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to update attribute table from a .csv and add new rows to apply geometry</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-update-attribute-table-from-a-csv-and-add/m-p/1241502#M63456</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# input parameters
fc = r"N:\...\db.gdb\TestPoints"  # path to the fc
csv = r"N:\...\testpoints.csv"  # path to csv
copy_fields = ["TextField", "IntegerField", "DoubleField"]  # list of the fields you want to copy. First field has to be a unique identifer


import arcpy
# read the csv, store its data in a dictionary
csv_dict = {row[0]: row for row in arcpy.da.SearchCursor(csv, copy_fields)}

# loop over the features with an UpdateCursor
with arcpy.da.UpdateCursor(fc, copy_fields) as cursor:
    for row in cursor:
        # get the csv data for that row
        key = row[0]
        try:
            new_row = csv_dict[key]
        except KeyError:  # row not found in csv
            print(f"Entry not found in csv: {copy_fields[0]} = {key}")
#            cursor.deleteRow()  # uncomment this to delete the feature
            continue
        # update the feature
        cursor.updateRow(new_row)
        del csv_dict[key]

# every feature that is left in the csv_dict is new
with arcpy.da.InsertCursor(fc, copy_fields) as cursor:
    for new_row in csv_dict.values():
        cursor.insertRow(new_row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 12:05:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-update-attribute-table-from-a-csv-and-add/m-p/1241502#M63456</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-12-15T12:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to update attribute table from a .csv and add new rows to apply geometry</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-update-attribute-table-from-a-csv-and-add/m-p/1241693#M63492</link>
      <description>&lt;P&gt;Thanks so much! This helps a lot&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 19:42:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-update-attribute-table-from-a-csv-and-add/m-p/1241693#M63492</guid>
      <dc:creator>jgstaley</dc:creator>
      <dc:date>2022-12-15T19:42:09Z</dc:date>
    </item>
  </channel>
</rss>

