select#
Keep selected rows, using a Python expression to define which rows to keep.
Note
This guide explains how to configure the select instruction. To learn about another instruction, go back to the Custom scripts available in Adverity overview.
Introduction#
Use the select instruction to find and keep rows in a data extract for which the Python expression evaluates to true
. Only
the rows of the data extract that are evaluated as true
are
kept, all other rows are removed.
Understanding the different select instructions#
There are a number of different select custom script instructions that can be used to keep or remove specific rows in your data extract based on the criteria you choose. The different types of select instruction are:
select - keep selected rows, using a Python expression to define which rows to keep
selecteq - keep rows with a value that matches the value you enter
selectne - remove rows with a value that matches the value you enter
selecttrue - keep rows that contain any value in a selected column
selectfalse - keep rows that are empty, or contain
null
or0
, in a selected columnselectgt - keep rows with a number greater than the number you enter
selectlt - keep rows with a number less than the number you enter
selectin - keep rows with a value that matches any of a list of values you enter
selectnotin - remove rows with a value that matches any of a list of values you enter
selectnone - keep rows in a selected column that are empty
selectnotnone - remove rows in a selected column that are empty
selectinvt - keep rows that match values in a value table
Creating a custom script transformation using the select instruction#
To create and configure a custom script using the select instruction, follow these steps:
In the Configuration step, select the select instruction.
To configure the custom script instruction, fill in the required fields below, as well as any optional fields you require:
- Where (required)
Enter a Python expression to use as search criteria. For example, you can enter the name of a column and a value within the column. Enter the name of the column between braces and the value to search for between quotes. For example,
{column_name}=='value to search'
.- Complement
Select this field to reverse the transformation. Any rows that match the search criteria are removed and the rows that do not match the criteria are kept.
- Missing
Enter a value with which to populate empty fields.
- Subtable
Enter the name for a subtable that you want to use within this custom script.
A subtable is a temporary table that only exists for this custom script. You can apply additional instructions within the same custom script to the subtable. However, the subtable cannot be used in any other custom scripts.
If a subtable does not exist for the current custom script, the transformation is applied to the data extract, and the enriched data is output into the subtable. If the subtable already exists for the custom script, the subtable is used as the input for the transformation and optionally as the output.
Example 1#
Transformation configuration#
- Where
{Campaign} == 'Brand'
- Complement
Do not select this field.
Data table before transformation#
Campaign |
Ad Group |
Clicks |
---|---|---|
Brand |
media |
7 |
Branding |
ecommerce |
3 |
Dashboard |
brand awareness |
18 |
Brand |
ecommerce |
4 |
Dashboard |
media|social |
5 |
Branding |
media |
11 |
Data table after transformation#
Campaign |
Ad Group |
Sum_Clicks |
---|---|---|
Brand |
media |
7 |
Brand |
ecommerce |
4 |
Example 2#
Transformation configuration#
- Where
{Campaign} == 'Brand'
- Complement
Select this field.
Data table before transformation#
Campaign |
Ad Group |
Clicks |
---|---|---|
Brand |
media |
7 |
Branding |
ecommerce |
3 |
Dashboard |
brand awareness |
18 |
Brand |
ecommerce |
4 |
Dashboard |
media|social |
5 |
Branding |
media |
11 |
Data table after transformation#
Campaign |
Ad Group |
Sum_Clicks |
---|---|---|
Branding |
ecommerce |
3 |
Dashboard |
brand awareness |
18 |
Dashboard |
media|social |
5 |
Branding |
media |
11 |