Page tree



Contents:

The cloud-based version of Trifacta Wrangler is now available! Read all about it, and register for your free account.

Contents:


NOTE: Transforms are a part of the underlying language, which is not directly accessible to users. This content is maintained for reference purposes only. For more information on the user-accessible equivalent to transforms, see Transformation Reference.

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

Transformation:

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

Transformation Name Rename columns
Parameter: Option Manual rename
Parameter: Column LengthX
Parameter: New column name 'LengthX_cm'

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

Transformation Name New formula
Parameter: Formula type Single row formula
Parameter: Formula (LengthX_cm * 0.393701)
Parameter: New column name 'LengthX_in'

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

Transformation Name Edit column with formula
Parameter: Columns LengthX_in
Parameter: Formula numformat(LengthX_in, '##.00')

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 delete the original columns if needed.

Rename multiple columns

Source:

column1column2column3column4column5
data1data2data3data4data5


Transformation:

Add prefix:

Transformation Name Rename columns
Parameter: Option Add prefix
Parameter: Columns column1,column2,column3,column4,column5
Parameter: Prefix 'new_'

new_column1new_column2new_column3new_column4new_column5
data1data2data3data4data5


Add suffix:

Transformation Name Rename columns
Parameter: Option Add suffix
Parameter: Columns new_column1,new_column2,new_column3,new_column4,new_column5
Parameter: Suffix 'a'

new_column1anew_column2anew_column3anew_column4anew_column5a
data1data2data3data4data5

Find and replace:

Transformation Name Rename columns
Parameter: Option Find and replace
Parameter: Columns new_column1,new_column2,new_column3,new_column4,new_column5
Parameter: Find '_column'
Parameter: Replace 'Field'

new_Field1anew_Field2anew_Field3anew_Field4anew_Field5a
data1data2data3data4data5

Manual rename:

Transformation Name Rename columns
Parameter: Option Manual rename
Parameter: Column 1 newField1a
Parameter: New Column 1 name 'firstColumn'
Parameter: Column 2 newField2a
Parameter: New Column 1 name 'secondColumn'

firstColumnsecondColumnnew_Field3anew_Field4anew_Field5a
data1data2data3data4data5

Use row as header:

Transformation Name Rename columns
Parameter: Option Use row(s) as column names
Parameter: Type Use a single row as column names
Parameter: Row number 2

data1data2data3data4data5
data6data7data8data9data10


 

Your Rating: Results: 1 Star2 Star3 Star4 Star5 Star 11 rates

This page has no comments.