Pivot Table (Data Management)

License Level:BasicStandardAdvanced

Summary

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

Illustration

Pivot Table illustration

Usage

Syntax

PivotTable_management (in_table, fields, pivot_field, value_field, out_table)
ParameterExplanationData Type
in_table

The table whose records will be pivoted.

Table View
fields
[fields,...]

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

Field
pivot_field

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

Field
value_field

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

Field
out_table

The table to be created.

Table

Code Sample

PivotTable Example (Python Window)

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

import arcpy
from arcpy import env

env.workspace = "C:/data"
arcpy.PivotTable_management("attributes.dbf", "OwnerID", "AttrTagNam", "AttrValueS", "C:/output/attribPivoted.dbf")
PivotTable Example 2 (Stand-alone Python 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
# Author: ESRI

# Import system modules
import arcpy
from arcpy import env

# Set workspace
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"

# Execute PivotTable
arcpy.PivotTable_management(in_table, fields, pivot_field, value_field, out_table)

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: No
ArcGIS for Desktop Standard: No
ArcGIS for Desktop Advanced: Yes
5/7/2015