<?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: Attribute table update using standalone table in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/attribute-table-update-using-standalone-table/m-p/1298497#M67957</link>
    <description>&lt;P&gt;Untested, supply your table and field names in lines 13 &amp;amp; 17.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

def mean(values):
    values = [v for v in values if v is not None]
    try:
        return sum(values) / len(values)
    except ZeroDivisionError:
        raise ValueError("No non-null values in input list!")

# get the morning and evening readings from the update table (dict with id as key)
update_rows = {
    i: [m, e]
    for i, m, e in arcpy.da.SearchCursor("UpdateTable", ["GaugeID", "Morning", "Evening"])
    }

# update the gauge layer
with arcpy.da.UpdateCursor("Gauges", ["GaugeID", "AverageReading"]) as cursor:
    for i, avg in cursor:
        try:
            avg = mean(update_rows[i])
        except KeyError:
            print("GaugeID not found in update table: " + str(i))
            continue
        except ValueError:
            print("Could not calculate average for GaugeID " + str(i))
            continue
        cursor.updateRow([i, avg])&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 13 Jun 2023 12:00:40 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-06-13T12:00:40Z</dc:date>
    <item>
      <title>Attribute table update using standalone table</title>
      <link>https://community.esri.com/t5/python-questions/attribute-table-update-using-standalone-table/m-p/1298482#M67956</link>
      <description>&lt;P&gt;I have a river gauge point layer whose attribute table has gaugid and average_reading fields. I also have a standalone table the has morning and evening readings field for each river gauge. The standalone table is fed readings using Field maps twice a day. I have published the layers on ArcGIS online.&lt;/P&gt;&lt;P&gt;I want a script that gets daily average for each gauge and then updates the average reading to the point attribute table in the average_reading field.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 10:39:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attribute-table-update-using-standalone-table/m-p/1298482#M67956</guid>
      <dc:creator>KELVINKARANJA</dc:creator>
      <dc:date>2023-06-13T10:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute table update using standalone table</title>
      <link>https://community.esri.com/t5/python-questions/attribute-table-update-using-standalone-table/m-p/1298497#M67957</link>
      <description>&lt;P&gt;Untested, supply your table and field names in lines 13 &amp;amp; 17.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

def mean(values):
    values = [v for v in values if v is not None]
    try:
        return sum(values) / len(values)
    except ZeroDivisionError:
        raise ValueError("No non-null values in input list!")

# get the morning and evening readings from the update table (dict with id as key)
update_rows = {
    i: [m, e]
    for i, m, e in arcpy.da.SearchCursor("UpdateTable", ["GaugeID", "Morning", "Evening"])
    }

# update the gauge layer
with arcpy.da.UpdateCursor("Gauges", ["GaugeID", "AverageReading"]) as cursor:
    for i, avg in cursor:
        try:
            avg = mean(update_rows[i])
        except KeyError:
            print("GaugeID not found in update table: " + str(i))
            continue
        except ValueError:
            print("Could not calculate average for GaugeID " + str(i))
            continue
        cursor.updateRow([i, avg])&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 13 Jun 2023 12:00:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attribute-table-update-using-standalone-table/m-p/1298497#M67957</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-06-13T12:00:40Z</dc:date>
    </item>
  </channel>
</rss>

