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.
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 code |
---|
rename: col: column_ref [prefix: 'strPrefix'] [suffix: 'strSuffix'] [mapping: [column1,'newColumn1Name'], [column2,'newColumn2Name']] [on: `patternOrLiteral`] [with: 'replacementString'] [sourceRowNumber: intRowNum] |
Token | Required? | Data Type | Description |
---|
rename | Y | transform | Name of the transform |
col | Y | string | Name of column or columns to rename |
prefix | N | string | (batch column) Prefix to prepend to the column name |
suffix | N | string | (batch column) Suffix to append to the column name |
mapping | N | array | (batch column) Array containing mappings from old column name and new column name |
on | N | string | (batch column) Pattern or string literal for which to search each column name |
with | N | string | (batch column) Replacement value for found pattern or string literal in column names |
sourcerownumber | N | integer | (batch column) Row number from the source data to use as the new names for the selected columns |
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. |
Required? | Data Type |
---|
Yes | String (column name) |
For batch rename using prefixes, this parameter specifies the string value with which to precede each of the column names.
Required? | Data Type |
---|
No | String |
For batch rename using suffixes, this parameter specifies the string value with which to append each of the column names.
Required? | Data Type |
---|
No | String |
An array describing the old names and new names for each column to rename.
Example:
Old column name | New column name |
---|
column1 | FirstName |
column2
| LastName |
column3
| Phone |
Transform step:
D code |
---|
rename mapping: [column1,'FirstName'],[column2,'LastName'],[column3,'Phone'] |
Required? | Data Type |
---|
No | Array |
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.
Required? | Data Type |
---|
No | String (pattern or literal) |
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.
Required? | Data Type |
---|
No | String (pattern or literal) |
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. |
Required? | Data Type |
---|
No | Integer (Positive value) |
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:
Object | LengthX | LengthY | LengthZ |
---|
ObjA | 10 | 20 | 30 |
ObjB | 3 | 4 | 5 |
ObjC | 6 | 9 | 12 |
Transformation:
Perhaps you know the units are centimeters. You can rename using the following:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'LengthX_cm' |
---|
Type | step |
---|
WrangleText | rename mapping: [LengthX, 'LengthX_cm'] |
---|
p01Name | Option |
---|
p01Value | Manual rename |
---|
p02Name | Column |
---|
p02Value | LengthX |
---|
p03Name | New column name |
---|
SearchTerm | Rename columns |
---|
|
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:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'LengthX_in' |
---|
Type | step |
---|
WrangleText | derive type:single value: (LengthX_cm * 0.393701) as:'LengthX_in' |
---|
p01Name | Formula type |
---|
p01Value | Single row formula |
---|
p02Name | Formula |
---|
p02Value | (LengthX_cm * 0.393701) |
---|
p03Name | New column name |
---|
SearchTerm | New formula |
---|
|
You might want to reformat the generated values using transformations like the following, which rounds the results to two decimal points:
D trans |
---|
RawWrangle | true |
---|
Type | step |
---|
WrangleText | set col:LengthX_in value:numformat(LengthX_in, '##.00') |
---|
p01Name | Columns |
---|
p01Value | LengthX_in |
---|
p02Name | Formula |
---|
p02Value | numformat(LengthX_in, '##.00') |
---|
SearchTerm | Edit column with formula |
---|
|
Repeat the above steps for the other length columns.
Results:
Object | LengthX_cm | LengthY_cm | LengthZ_cm | LengthX_in | LengthY_in | LengthZ_in |
---|
ObjA | 10 | 20 | 30 | 3.94 | 7.87 | 11.81 |
ObjB | 3 | 4 | 5 | 1.18 | 1.57 | 1.97 |
ObjC | 6 | 9 | 12 | 2.36 | 3.54 | 4.72 |
You can delete the original columns if needed.
Source:
column1 | column2 | column3 | column4 | column5 |
---|
data1 | data2 | data3 | data4 | data5 |
Transformation:
Add prefix:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'new_' |
---|
Type | step |
---|
WrangleText | rename col: column1,column2,column3,column4,column5 prefix: 'new_' |
---|
p01Name | Option |
---|
p01Value | Add prefix |
---|
p02Name | Columns |
---|
p02Value | column1,column2,column3,column4,column5 |
---|
p03Name | Prefix |
---|
SearchTerm | Rename columns |
---|
|
new_column1 | new_column2 | new_column3 | new_column4 | new_column5 |
---|
data1 | data2 | data3 | data4 | data5 |
Add suffix:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'a' |
---|
Type | step |
---|
WrangleText | rename col: new_column1,new_column2,new_column3,new_column4,new_column5 suffix: 'a' |
---|
p01Name | Option |
---|
p01Value | Add suffix |
---|
p02Name | Columns |
---|
p02Value | new_column1,new_column2,new_column3,new_column4,new_column5 |
---|
p03Name | Suffix |
---|
SearchTerm | Rename columns |
---|
|
new_column1a | new_column2a | new_column3a | new_column4a | new_column5a |
---|
data1 | data2 | data3 | data4 | data5 |
Find and replace:
D trans |
---|
RawWrangle | true |
---|
p03Value | '_column' |
---|
Type | step |
---|
WrangleText | rename col: new_column1,new_column2,new_column3,new_column4,new_column5 on:'_column' with: 'Field' |
---|
p01Name | Option |
---|
p01Value | Find and replace |
---|
p02Name | Columns |
---|
p02Value | new_column1,new_column2,new_column3,new_column4,new_column5 |
---|
p03Name | Find |
---|
p04Value | 'Field' |
---|
p04Name | Replace |
---|
SearchTerm | Rename columns |
---|
|
new_Field1a | new_Field2a | new_Field3a | new_Field4a | new_Field5a |
---|
data1 | data2 | data3 | data4 | data5 |
Manual rename:
D trans |
---|
RawWrangle | true |
---|
p03Value | 'firstColumn' |
---|
WrangleText | rename mapping: [newField1a,'firstColumn'],[newField2a,'secondColumn'] |
---|
p01Name | Option |
---|
p03Name | New Column 1 name |
---|
p04Value | newField2a |
---|
SearchTerm | Rename columns |
---|
Type | step |
---|
p05Name | New Column 1 name |
---|
p01Value | Manual rename |
---|
p02Name | Column 1 |
---|
p02Value | newField1a |
---|
p05Value | 'secondColumn' |
---|
p04Name | Column 2 |
---|
|
firstColumn | secondColumn | new_Field3a | new_Field4a | new_Field5a |
---|
data1 | data2 | data3 | data4 | data5 |
Use row as header:
D trans |
---|
RawWrangle | true |
---|
p03Value | 2 |
---|
Type | step |
---|
WrangleText | rename sourcerownumber: 2 |
---|
p01Name | Option |
---|
p01Value | Use row(s) as column names |
---|
p02Name | Type |
---|
p02Value | Use a single row as column names |
---|
p03Name | Row number |
---|
SearchTerm | Rename columns |
---|
|
data1 | data2 | data3 | data4 | data5 |
---|
data6 | data7 | data8 | data9 | data10 |
D s also |
---|
label | wrangle_transform_rename |
---|
|