I'm working on an ArcGIS project where the table contains temporal data, with relevant fields that contain:
The goal is to calculate the fourth by summing all of the attributes taxable sales for each zip code across all the years there is data for. E.g. If there are 10 attribute each for a different year for the same zip code, I want to sum all 10 of those sales cells in the Sales_Cumulative for all of 10 of those attributes.
I tried to see if I could use the field calculator function, but was not familiar enough to work out how to calculate for what I needed.
My other option is summing them outside of ArcGIS Pro in Excel.
You could use the tools Summary Statistics
, Add Join
, Calculate Field
, and Remove Join
.
Summary Statistics
to calculate the cumulative annual saleSummary Statistics
using the field Zipcode
Use Calculate Field
to set Sales_Cumulative
to !Sales_Statistics.SUM_Sales_Annual!
Remove the join by using Remove Join
Here is a screenshot of the model:
Alternatively, you could use Python and a Spatially enabled DataFrame:
import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor
table = r"Default.gdb\Sales"
# load table
sdf = pd.DataFrame.spatial.from_table(filename=table, skip_nulls=False)
# calulate the total sales by zip code
total_sales_by_zipcode = sdf.groupby(["Zipcode"])["Sales_Annual"].sum()
sdf["Sales_Cumulative"] = sdf["Zipcode"].apply(lambda x: total_sales_by_zipcode[x])
sdf.spatial.to_table(location=table, overwrite=True)
Notes:
sdf.spatial.to_table
, all field names are suddenly lower case.skip_nulls
when reading the table, otherwise no data is read due to a "bug". See here.