Batch Update Fields (Data Management)

Summary

Transforms fields in a table or feature class based on schema defined in the definition table and creates a new table or feature class.

You can do the following using this tool:

  • Add new fields.
  • Update existing fields.
  • Reorder fields.
  • Change field types.
  • Change field properties.
  • Assign or update field aliases.
  • Calculate field values based on existing fields using Python.
  • Remove fields.

Usage

  • The input table can be a feature class or a table. The tool outputs a new feature class or table with the updated schema.

  • The schema changes for the output table are defined by the Output Schema Definition Table parameter.

    The following is an example of a definition table:

    Example of a definition table

    If the Output Schema Definition Table parameter value includes the following field names, as in the example above, the corresponding parameter values will be populated automatically:

    • Target field
    • Source field
    • Type
    • Decimals/Length
    • Alias
    • Script

  • The tool calculates new fields using existing fields by providing a script field in the definition table.

    An example value in the Script field of the definition table is !TOTPOP!/!AREA!, which calculates the Population Density field. Field names must be enclosed in exclamation points.

  • The tool can create additional fields that are dependent on other field calculations. For example, the Bev_Index field is calculated using the Bev_Per_Capita field, which is also calculated when the tool is run.

  • Use the Script File parameter for multiple line Python calculations. To use a script file, create a file with Python functions, and reference the functions in the definition table.

    The following is an example of script code for a target field named Bev_Per_Capita:

    • A field named Script in the Output Schema Definition Table parameter value with a value of Bev_Per_Capita(!Bev_Total!, !TOTPOP!)
    • A Script File parameter value with the following function:
      
      def Bev_Per_Capita(Bev_Total, TOTPOP):
          return Bev_Total / TOTPOP

    The following is an example showing the attribute table before and after running the tool:

    Batch Update Fields tool example

Parameters

LabelExplanationData Type
Input Table

The input table or feature class.

Table View
Output Table

The output table or feature class containing the updated fields.

Table
Output Schema Definition Table

A table containing the field definitions and calculations that will be used to create the output.

Table View
Script File
(Optional)

A Python file that stores multiple line Python functions to perform calculations for the Output Table parameter fields.

File
Output Field Name
(Optional)

The field name from the definition table that contains the target field names for the output table.

Field
Source Field Name
(Optional)

The field name from the definition table that contains the source field names from the input table.

Field
Output Field Type
(Optional)

The field in the Output Schema Definition Table parameter value that defines the data types for the output table. The field is expected to be of Text type.

The field in the field_definition_table that defines the data types for the output table. The field is expected to be of Text type.

The following values are supported:

  • BigInteger—64-bit Integer
  • Blob—Binary Large Object
  • Date—Date
  • DateOnly—Date Only
  • Double—Double-precision floating-point number
  • GlobalID—Global ID
  • GUID—Globally Unique Identifier
  • Integer (or Long)—32-bit Integer
  • Raster—Raster
  • Float (or Single)—Single-precision floating-point number
  • Short (or SmallInteger)—16-bit Integer
  • Text (or String)—Character string
  • TimeOnly—Time Only
  • TimestampOffset—Timestamp Offset
Field
Output Field Decimals or Length
(Optional)

The field name from the definition table that defines the number of decimals or the length of the field for the output fields.

Field
Output Field Alias
(Optional)

The field name from the definition table that defines the alias names for the fields of the output table.

Field
Output Field Script
(Optional)

The field name from the definition table that defines the calculations for the output fields.

Field

arcpy.management.BatchUpdateFields(in_table, out_table, field_definition_table, {script_file}, {output_field_name}, {source_field_name}, {output_field_type}, {output_field_decimals_or_length}, {output_field_alias}, {output_field_script})
NameExplanationData Type
in_table

The input table or feature class.

Table View
out_table

The output table or feature class containing the updated fields.

Table
field_definition_table

A table containing the field definitions and calculations that will be used to create the output.

Table View
script_file
(Optional)

A Python file that stores multiple line Python functions to perform calculations for the out_table parameter fields.

File
output_field_name
(Optional)

The field name from the definition table that contains the target field names for the output table.

Field
source_field_name
(Optional)

The field name from the definition table that contains the source field names from the input table.

Field
output_field_type
(Optional)

The field in the Output Schema Definition Table parameter value that defines the data types for the output table. The field is expected to be of Text type.

The field in the field_definition_table that defines the data types for the output table. The field is expected to be of Text type.

The following values are supported:

  • BigInteger—64-bit Integer
  • Blob—Binary Large Object
  • Date—Date
  • DateOnly—Date Only
  • Double—Double-precision floating-point number
  • GlobalID—Global ID
  • GUID—Globally Unique Identifier
  • Integer (or Long)—32-bit Integer
  • Raster—Raster
  • Float (or Single)—Single-precision floating-point number
  • Short (or SmallInteger)—16-bit Integer
  • Text (or String)—Character string
  • TimeOnly—Time Only
  • TimestampOffset—Timestamp Offset
Field
output_field_decimals_or_length
(Optional)

The field name from the definition table that defines the number of decimals or the length of the field for the output fields.

Field
output_field_alias
(Optional)

The field name from the definition table that defines the alias names for the fields of the output table.

Field
output_field_script
(Optional)

The field name from the definition table that defines the calculations for the output fields.

Field

Code sample

BatchUpdateFields example (stand-alone script)

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

import arcpy
arcpy.management.BatchUpdateFields(
    "zip_codes", "MyProject.gdb\zip_codes_BatchUpdateFields",
    "DATA_TRANSFORMATION.csv", r"C:\BatchUpdate\script.py", "TARGET",
    "SOURCE", "DATATYPE", "DECIMALS", "ALIAS", "SCRIPT")

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics