Label | Explanation | Data Type |
Input Table | The table containing the records to be pivoted. | Table View |
Input Fields | The fields that define 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. | Table |
Available with Advanced license.
Summary
Creates a table from the input table by reducing redundancy in records and flattening one-to-many relationships.
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 values must be 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 is determined by the number of input fields you choose, plus one field for each unique Pivot Field value. The number of records in the output table is determined by the unique combination of values between the chosen input fields and the pivot field.
The tool will fail if the selected Pivot Field value contains Null values.
Parameters
arcpy.management.PivotTable(in_table, fields, pivot_field, value_field, out_table)
Name | Explanation | Data Type |
in_table | The table containing the records to be pivoted. | Table View |
fields [fields,...] | The fields that define 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. | Table |
Code sample
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")
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)
Environments
Licensing information
- Basic: No
- Standard: No
- Advanced: Yes