Calculate Weighted Average¶
See also
This is the geoprocessing interface for calculating the weighted average of value(s) of a (set of) column(s) in a table based on the distribution of values in another (set of) column(s) in the table.
Determine an areawide average score or value based on subarea distributions of activity (populationweighted average access to jobs, e.g.).
 Input table : ArcGIS Table/Table View/Feature Class/Feature Layer
 The table containing values for which averages are desired and weight fields for calculating the appropriate average values.
 Value fields : [Field,…]
 The fields in the input table for which the average value based on values in each weight field will be reported.
 Weight fields : [Field,…]
 The fields in the input table that will be applied to each value field as weights to determine the value field’s average value across all rows in the table. Weighted average values for each value field are reported in separate rows for each weight field.
 Select features from the input table : SQL Expression, optional
 A SQL expression applied to the input table to focus the weighted average calculation on records matching the criteria defined by the expression.
 Select subset : Boolean, optional
 If True, a “secondary” table or feature class may be used to select records from the input table to focus the weighted average calculation on records matching criteria in the secondary table or having a specified spatial relationship to the secondary feature class. (Default is False.)
 Selection method : {“SPATIAL”, “TABULAR”}, optional
 If select subset is True, specify whether the selection of records in the input table will be based on a spatial relationship to a secondary feature class (“SPATIAL”) or on a lookup relationship to a secondary table (“TABULAR”). If “SPATIAL”, input table must be a feature class or feature layer.
 Reference layer : ArcGIS Feature Class or Feature Layer, optional
 If selection method is “SPATIAL,” the secondary feature class or feature layer to use as the basis for spatial selection of features in input table.
 Select features from reference layer : SQL Express, optional
 If selection method is “SPATIAL,” optionally provide a SQL expression to limit the features in reference layer used for the spatial selection of features in input table.
 Spatial relationship : String, optional
 If selection method is “SPATIAL,” define the spatial relationship to use when selecting features in input table. All ArcGIS overlap_types are valid.
 Search distance : Linear Unit, optional
 If selection method is “SPATIAL,” define the search tolerance to guide the selection of features from the input table based on their spatial relationship to features in the reference layer. If blank, a strict spatial selection is applied.
 Reference table : ArcGIS Table or Table View, optional
 If selection method is “TABULAR,” the secondary table or table view to use as the basis for tabular selection (through lookup) of records in input table.
 Refrence table key field : Field, optional
 If selection method is “TABULAR,” the field in reference table containing values to lookup in input table (based on its values in the input table lookup field) for inclusion in the weighted average calculation.
 Input table lookup field : Field, optional
 If selection method is “TABULAR,” the field in input table containing values corresponding to those in the reference table key field (in the reference table). Only input table records having values in this field that match those listed in the reference table key field will be included in the weighte average calculation.
 Select records from reference table : SQL Expression, optional
 If selection method is “TABULAR,” optionally provide a SQL expression to limit the records in reference table used for the tabular lookup of records in input table.
 Output table : ArcGIS Table
 The output table storing the weighted averages. The output table is organized in to rows representing each weight field and columns containing the weighed average values for each value field for that weight field.
See also
weightedAverage

gp_calcWeightedAverage.
weightedAverage
(table, value_fields, weight_fields)[source]¶ Calculate the average value(s) of a (list of) column(s) in a table, weighted by the values in another column or list of columns in the table.
Parameters:  table (ArcGIS Table or ArcGIS Table View) – The table with value_fields and weight_fields from which to calculate and tabulate weighted averages.
 value_fields ([String,..]) – A list of field names whose values will be averaged.
 weight_fields ([String,..]) – A list of field names whose values will provide weights that influence the averages calculated from value_fields.
Returns: out_array – Returns an output array with weighted averages reported such that each weight_field is in its own row and each column provides the weighted average of each value_field as weighted by the weight_field reflected in that row.
Return type: Numpy array
Notes
When values in a table are recorded in an aggregated manner such that a single record may represent a common condition or value for a collective, a simple average of column values for that table offers limited insight into typical conditions for members of that collective. In these cases, a weighted average is needed to describe the average value for the collective.
An example of this is geographic aggregation into zones. Each zone may have multiple people and different population groups residing within it. For measures calculated at the zone level, a simple average of those measures across zones will not reflect typical conditions for the people living in those zones. A weighted average takes into account the conditions as they apply on a per person basis rather than on a per zone basis.
See the example below showing commute times and distaces for male and female populations in three zones. The average commute time for males in the combined threezone area cannot be calculated as the sum of the “commute_time” column divided by 3 (the zonal average commute time) because the distribution of the male population is not uniform across all zones. Most males live in Zone 1 with an estimated commute time of 26 minutes. Thus, the average for all males in the threezone area will be closer to 26 minutes than to the 16 minutes shown for zone 2, where only 5 males reside. The weighted average commute time for males is actually 24.2, as shown in the example result array.
The average commute time for females differs from that for males because the distribution of females across the zones differs from the male population distribution.
Example input table
Zone_ID Male_pop Female_pop Commute_time Commute_dist 1 100 90 26 8.5 2 5 9 16 5.3 3 27 40 19 7.1 Example result array
WeightField Commute_time Commute_dist Male_pop 24.2 8.1 Female_pop 23.3 7.9