Summary
Reads a table and a set of fields and creates a new table containing unique field values and the number of occurrences of each unique field value.
Usage
The output table will contain the field Frequency and the specified frequency field(s) and summary field(s).
The output table will contain the frequency for each unique combination of the specified frequency field(s).
If a summary field is specified, the unique attribute values of the frequency calculation are summarized by the numeric attribute values of each summary field.
When using layers, only the currently selected features are used in calculations.
Syntax
Frequency(in_table, out_table, frequency_fields, {summary_fields})
Parameter | Explanation | Data Type |
in_table | The table containing the field(s) that will be used to calculate frequency statistics. | Table View; Raster Layer |
out_table | The output table that will store the frequency statistics. | Table |
frequency_fields [frequency_fields,...] | The field(s) used to calculate frequency statistics. Each unique combination of field values will be included as a new row in the output table. | Field |
summary_fields [summary_fields,...] (Optional) | The attribute field(s) to sum and add to the output table. Values will be summed for each unique combination of frequency fields. Null values are excluded from this calculation. | Field |
Code sample
The following Python window script demonstrates how to use the Frequency function in immediate mode.
import arcpy
arcpy.env.workspace = "C:/data/Portland.gdb/Taxlots"
arcpy.Frequency_analysis("taxlots",
"C:/output/output.gdb/tax_frequency",
["YEARBUILT", "COUNTY"],
["LANDVAL", "BLDGVAL", "TOTALVAL"])
The following stand-alone script demonstrates how to use the Frequency function.
# Description: Run Frequency on a table
# Import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = "C:/data/Portland.gdb/Taxlots"
# Set local variables
inTable = "taxlots"
outTable = "C:/output/output.gdb/tax_frequency"
frequencyFields = ["YEARBUILT", "COUNTY"]
summaryFields = ["LANDVAL", "BLDGVAL", "TOTALVAL"]
# Execute Frequency
arcpy.Frequency_analysis(inTable, outTable, frequencyFields, summaryFields)
The following stand-alone script demonstrates how to use many geoprocessing scripting functions, including the Frequency function.
# Description: Break all multipart features into single part features,
# and generate a report of which features were separated.
# Import system modules
import arcpy
# Create variables for the input and output feature classes
inFeatureClass = "c:/data/gdb.gdb/vegetation"
outFeatureClass = "c:/data/gdb.gdb/vegetation_singlepart"
try:
# Create list of all fields in inFeatureClass
fieldNameList = [field.name for field in arcpy.ListFields(inFeatureClass)]
# Add a field to the input this will be used as a unique identifier
arcpy.AddField_management(inFeatureClass, "tmpUID", "double")
# Determine what the name of the Object ID is
OIDFieldName = arcpy.Describe(inFeatureClass).OIDFieldName
# Calculate the tmpUID to the OID
arcpy.CalculateField_management(inFeatureClass, "tmpUID",
"[" + OIDFieldName + "]")
# Run the tool to create a new fc with only singlepart features
arcpy.MultipartToSinglepart_management(inFeatureClass, outFeatureClass)
# Check if there is a different number of features in the output
# than there was in the input
inCount = int(arcpy.GetCount_management(inFeatureClass)[0])
outCount = int(arcpy.GetCount_management(outFeatureClass)[0])
if inCount != outCount:
# If there is a difference, print out the FID of the input
# features which were multipart
arcpy.Frequency_analysis(outFeatureClass,
outFeatureClass + "_freq", "tmpUID")
# Use a search cursor to go through the table, and print the tmpUID
print("Multipart features from {0}".format(inFeatureClass))
for row in arcpy.da.SearchCursor(outFeatureClass + "_freq",
["tmpUID"], "FREQUENCY > 1"):
print(int(row[0]))
else:
print("No multipart features were found")
except arcpy.ExecuteError:
print(arcpy.GetMessages())
except Exception as err:
print(err)
Environments
Licensing information
- Basic: No
- Standard: No
- Advanced: Yes