频数 (分析)

描述

读取表和一组字段,并创建一个包含唯一字段值以及各唯一字段值所出现次数的新表。

使用方法

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

  • 输出表将包含指定频数字段各种唯一组合的频数。

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

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

语法

arcpy.analysis.Frequency(in_table, out_table, frequency_fields, {summary_fields})
参数说明数据类型
in_table

表中包含将用于计算频数统计值的字段。

Table View; Raster Layer
out_table

输出表用于存储频数统计数据。

Table
frequency_fields
[frequency_fields,...]

该字段用于计算频数统计数据。字段值的每种唯一组合都将作为新的一行包括在输出表中。

Field
summary_fields
[summary_fields,...]
(可选)

该属性字段用于求和或添加到输出表。值将根据频数字段的各种唯一组合进行求和。空值被排除在此计算之外。

Field

代码示例

频数示例(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 Frequency 函数。

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"])
频数示例 2(独立脚本)

以下独立脚本演示了如何使用 Frequency 函数。

# 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)
频数示例 3(独立脚本)

以下独立脚本演示了如何使用多个地理处理脚本函数(包括 Frequency 函数)。

# 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)

许可信息

  • Basic: 是
  • Standard: 是
  • Advanced: 是

相关主题