Page tree

 

Support | BlogContact Us | 844.332.2821

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

D toc

Excerpt

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

Info

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

Tip

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. 

D s
snippetBasic

Rename a single column:

D code

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.

D s
snippetParameters

D code

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

D s lang notes

col

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

Info

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

 

D s
snippetusage

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. 

D s
snippetusage

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. 

D s
snippetusage

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:

D code

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


D s
snippetusage

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. 

D s
snippetusage

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. 

D s
snippetusage

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.

Info

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


D s
snippetusage

Required?Data Type
NoInteger (Positive value)

D s
snippetExamples

Rename a column

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

Tip

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:

D code

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:

D code

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:

D code

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

Info

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:

D code

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

new_column1new_column2new_column3new_column4new_column5
data1data2data3data4data5


Add suffix:

D code

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

new_column1anew_column2anew_column3anew_column4anew_column5a
data1data2data3data4data5

Find and replace:

D code

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:

D code

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

firstColumnsecondColumnnew_Field3anew_Field4anew_Field5a
data1data2data3data4data5

Use row as header:

D code

rename sourcerownumber: 2

data1data2data3data4data5
data6data7data8data9data10


D s also
labelwrangle_transform_rename