# 频数 (Analysis)

## 用法

• 输出表将包含字段频数 (Frequency) 以及输入所指定的频数字段和汇总字段。

• 输出表将包含所指定频数字段的所有属性值组合的频数计算（结果）。

• 如果指定了汇总字段，则频数计算结果的唯一属性值将由每个汇总字段的数值型属性值进行汇总。

• 使用图层时，仅使用图层中当前所选的要素进行计算。

## 语法

Frequency_analysis (in_table, out_table, frequency_fields, {summary_fields})
 参数 说明 数据类型 in_table 表中包含将用于计算频数统计值的字段。该表可以是 INFO 或 OLE DB 表、dBASE 或 VPF 表或者是要素类表。 Table View; Raster Layer out_table 用于存储所计算的频数统计值的表。 Table frequency_fields[frequency_fields,...] 将用于计算频数统计值的属性字段。 Field summary_fields[summary_fields,...](可选) 进行求和或添加到输出表的属性字段。空值被排除在此计算之外。 Field

## 代码实例

``````import arcpy
from arcpy import env
env.workspace = "C:/data/Portland.gdb/Taxlots"
arcpy.Frequency_analysis("taxlots", "C:/output/output.gdb/tax_frequency",["YEARBUILT", "COUNTY"], ["LANDVAL", "BLDGVAL", "TOTALVAL"])
``````

``````# Name: Frequency_Example2.py
# Description: Run Frequency on a table

# Import system modules
import arcpy
from arcpy import env

# Set environment settings
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)
``````

``````# Name: Frequency_Example3.py
# Description: Break all multipart features into singlepart 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

# 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).getOutput(0))
outCount = int(arcpy.GetCount_management(outFeatureClass).getOutput(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 e:
print e
``````

## 许可信息

ArcGIS for Desktop Basic:否
ArcGIS for Desktop Standard:否