Pivot Table (Data Management)

Available with Advanced license.

Summary

Creates a table from the input table by reducing redundancy in records and flattening one-to-many relationships.

Illustration

Pivot Table tool illustration

Usage

  • This tool is typically used to reduce redundant records and flatten one-to-many relationships.

  • The combination of the Input Fields, Pivot Field, and Value Field parameter values must be unique. Use the Frequency tool to determine if the combination is unique.

  • If the Pivot Field value is a text field, its values must begin with a character (for example, a2) and not a number (for example, 2a). If the value of the first record begins with a number, all the output values will be 0.

  • If the Pivot Field value is a numeric type, its value will be appended to its original field name in the output table.

  • The number of fields in the output table will be determined by the number of input fields you specify, plus one field for each unique Pivot Field value. The number of records in the output table will be determined by the unique combination of values between the specified input fields and the pivot field.

  • The tool will fail if the Pivot Field value contains Null values.

Parameters

LabelExplanationData Type
Input Table

The table containing the records that will be pivoted.

Table View
Input Fields

The fields that define the records that will be included in the output table.

Field
Pivot Field

The field whose record values will be used to generate the field names in the output table.

Field
Value Field

The field whose values will populate the pivoted fields in the output table.

Field
Output Table

The table that will be created containing the pivoted records.

Table

arcpy.management.PivotTable(in_table, fields, pivot_field, value_field, out_table)
NameExplanationData Type
in_table

The table containing the records that will be pivoted.

Table View
fields
[fields,...]

The fields that define the records that will be included in the output table.

Field
pivot_field

The field whose record values will be used to generate the field names in the output table.

Field
value_field

The field whose values will populate the pivoted fields in the output table.

Field
out_table

The table that will be created containing the pivoted records.

Table

Code sample

PivotTable example 1 (Python window)

The following Python window script demonstrates how to use the PivotTable function in immediate mode.


import arcpy
arcpy.env.workspace = "C:/data"
arcpy.management.PivotTable("attributes.dbf", "OwnerID", "AttrTagNam", 
                            "AttrValueS", "C:/output/attribPivoted.dbf")
PivotTable example 2 (stand-alone script)

The following Python script demonstrates how to use the PivotTable function in a stand-alone script.

# Name: PivotTable_Example2.py
# Description: Pivot the attributes table by the specified fields

# Import system modules
import arcpy

# Set workspace
arcpy.env.workspace = "C:/data"

# Set local variables
in_table = "attributes.dbf"
fields = "OwnerID"
pivot_field = "AttrTagNam"
value_field = "AttrValueS"
out_table = "C:/output/attribPivot.dbf"

# Run PivotTable
arcpy.management.PivotTable(in_table, fields, pivot_field, value_field, out_table)

Related topics