convert#
Convert values in a specific column in a data extract by specifying the original and new values, or using a Python string method as a converter.
Note
This guide explains how to configure the convert instruction. To learn about another instruction, go back to the Custom scripts available in Adverity overview.
Introduction#
Use the convert instruction to convert the values in a column of a data extract by specifying the original value and the value that it should be converted into.
You can also use a Python string method as a converter. For example, use
the Python expression capitalize
to make the first character of a
string upper case and all other characters in the string lower case.
Note
The Create or Edit Columns standard transformation enables you to edit the values in your data extract in a few easy steps, instead of using a custom script. For more information, see Create or Edit Columns.
Understanding the different convert instructions#
There are a number of different convert custom script instructions that can be used to convert specific types of data or to convert data in a specific way. The different types of convert instruction are:
convert - convert values in a specific column in a data extract by specifying the original and new values, or using a Python string method as a converter
convertx - convert values in a selected column in a data extract using a Python expression
convertall - convert all values in a data extract using a Python string method
convertallx - convert all the values in a data extract using a Python expression
convertdates - convert date characters in a string into Python datetime format
convertduration - convert duration data into the ISO 8601 format
convertnumbers - convert the numerical characters in a string into a number
convertpacked - convert the keys and values in a dictionary using a Python expression
convertunix - convert a UNIX timestamp into an easy-to-read datetime format
Creating a custom script transformation using the convert instruction#
To create and configure a custom script using the convert instruction, follow these steps:
In the Instructions step, select the convert instruction.
To configure the custom script instruction, fill in the following fields. Required fields are marked with an asterisk (*).
- Fields
Enter the name of the column containing the values to convert.
- Converter
To use a Python expression as a converter, select String and enter the Python expression to use as a converter. For a full list of compatible converters, see the Python documentation.
To simply convert values from one value to another, follow these steps:
Select Object from the drop-down menu to the right of Converter.
In the text field to the right of Object, enter the value to be converted.
Select the type in which the value is to be converted. For example, to convert a value into an integer, select Integer.
Enter the new value into which to convert.
(Optional) Click Add to convert another value using the same instruction.
- Fail on Error
Select this field to stop the transformation instruction if an error occurs.
- Errorvalue
Enter the value with which to populate the field if an error occurs.
Example#
Transformation configuration#
- Fields
Campaign
Ad Group
- Converter
capitalize
Data table before transformation#
Campaign |
Ad Group |
Clicks |
---|---|---|
brand |
media |
75856 |
outreach |
weekend ecommerce |
38753 |
organic growth |
socials |
99651 |
Data table after transformation#
Campaign |
Ad Group |
Clicks |
---|---|---|
Brand |
Media |
75856 |
Outreach |
Weekend Ecommerce |
38753 |
Organic Growth |
Socials |
99651 |