Rename Transform

NOTE: Transforms are a part of the underlying language that is not directly accessible to users. This content is maintained for reference purposes only.

Renames one or more columns based on specified names, patterns, row values, or prefixes and suffixes.

NOTE: Column names are case-insensitive and cannot begin with whitespace.

Tip: To prevent potential issues with downstream systems, you should limit your column lengths to no more than 128 characters.

Other ways to rename:

  • It's easier to rename columns through the user interface.
    • To rename a single column, double-click the column name or select Rename... from the column drop-down.
    • To rename multiple columns, you can select values in the Column Browser and perform batch renames. See Rename Columns.
  • Transforms that generate new columns might support the as parameter, which enables specifying the name of the new column. Using the as parameter avoids the extra step of adding a rename transform after column generation.

Basic Usage

Rename a single column:

rename mapping: [oldName,'NewName']

Output: Renames the column OldName to NewName.

Rename multiple columns:

This transform supports multiple methods for renaming two or more columns in a single step. See below for examples.

Parameters

rename: col: column_ref [prefix: 'strPrefix'] [suffix: 'strSuffix'] [mapping: [column1,'newColumn1Name'], [column2,'newColumn2Name']] [on: `patternOrLiteral`] [with: 'replacementString'] [sourceRowNumber: intRowNum]

TokenRequired?Data TypeDescription
renameYtransformName of the transform
colYstringName of column or columns to rename
prefixNstring(batch column) Prefix to prepend to the column name
suffixNstring(batch column) Suffix to append to the column name
mappingNarray(batch column) Array containing mappings from old column name and new column name
onNstring(batch column) Pattern or string literal for which to search each column name
withNstring(batch column) Replacement value for found pattern or string literal in column names
sourcerownumberNinteger(batch column) Row number from the source data to use as the new names for the selected columns

For more information on syntax standards, see Language Documentation Syntax Notes.

col

Identifies the column or columns to which to apply the transform.

NOTE: For renames of one or more columns to explicit names, specify the source and target columns using the mapping parameter instead.

Usage Notes:

Required?Data Type
YesString (column name)

prefix

For batch rename using prefixes, this parameter specifies the string value with which to precede each of the column names.

Usage Notes:

Required?Data Type
NoString

suffix

For batch rename using suffixes, this parameter specifies the string value with which to append each of the column names.

Usage Notes:

Required?Data Type
NoString

mapping

An array describing the old names and new names for each column to rename.

Example:

Old column nameNew column name
column1FirstName
column2
LastName
column3
Phone

Transform step:

rename mapping: [column1,'FirstName'],[column2,'LastName'],[column3,'Phone']

Usage Notes:

Required?Data Type
NoArray

on

For batch rename using find and replace, this parameter specifies the pattern or string literal to use to match values.

Replacement values are specified with the with parameter.

Usage Notes:

Required?Data Type
NoString (pattern or literal)

with

For batch rename using find and replace, this parameter specifies the literal string values with which to replace the found pattern.

Find patterns and values are specified with the on parameter.

Usage Notes:

Required?Data Type
NoString (pattern or literal)

sourcerownumber

The row number from the original source data which contains the values to use to rename all columns in the dataset. The row is removed from its original position.

NOTE: If source row number information is no longer available, this method cannot be used for column rename.

Usage Notes:

Required?Data Type
NoInteger (Positive value)

Examples

Rename a column

In the following dataset, the length columns do not include any units of measure.

Tip: For downstream consumption, any column that contains a measure should include the units of measure in the column name. Avoid including units of measure in cell values, which forces the column to be retyped as String type.

Source:

ObjectLengthXLengthYLengthZ
ObjA102030
ObjB345
ObjC6912

Transform:

Perhaps you know the units are centimeters. You can rename using the following:

rename mapping: [LengthX, 'LengthX_cm']

Now, you want to convert the units of measure to inches. You can use the derive transform to convert values and generate a new column name:

derive type:single value: (LengthX_cm * 0.393701) as:'LengthX_in'

You might want to reformat the generated values using transforms like the following, which rounds the results to two decimal points:

set col:LengthX_in value:NUMFORMAT(LengthX_in, '##.00')

NOTE: The set transform does not support the as parameter.

Repeat the above steps for the other length columns.

Results:

ObjectLengthX_cmLengthY_cmLengthZ_cmLengthX_inLengthY_inLengthZ_in
ObjA1020303.947.8711.81
ObjB3451.181.571.97
ObjC69122.363.544.72

You can drop the original columns if needed.

Rename multiple columns

Source:

column1column2column3column4column5
data1data2data3data4data5


Transform:

Add prefix:

rename col: column1,column2,column3,column4,column5 prefix: 'new_'

new_column1new_column2new_column3new_column4new_column5
data1data2data3data4data5

Add suffix:

rename col: new_column1,new_column2,new_column3,new_column4,new_column5 suffix: 'a'

new_column1anew_column2anew_column3anew_column4anew_column5a
data1data2data3data4data5

Find and replace:

rename col: new_column1,new_column2,new_column3,new_column4,new_column5 on:'_column' with: 'Field'

new_Field1anew_Field2anew_Field3anew_Field4anew_Field5a
data1data2data3data4data5

Manual rename:

rename mapping: [newField1a,'firstColumn'],[newField2a,'secondColumn']

firstColumnsecondColumnnew_Field3anew_Field4anew_Field5a
data1data2data3data4data5

Use row as header:

rename sourcerownumber: 2

data1data2data3data4data5
data6data7data8data9data10

Was this page helpful? Let us know how we did:

Send feedback about...

Google Cloud Dataprep Documentation
Need help? Visit our support page.