The 'dict' function, in association with the 'get' function enables you to create a dictionary and add new values in a new field (Addfieldx), based on the values from another field. With the same idea, it is also possible to use these two function to modify the values of an existing field (convertx).
Basically, this function works similarly as a mapping table and helps introduce/modify a value based on another value.
EXAMPLES
Addfieldx: Adding a value to a new field based on the value from another field
Field name: "New_field"
Python expression: dict([('www.adverity.co','USA'),
('pt.adverity.com','POR')]).get({page}[0:15])
=> If the first 15 characters of the value from field {page} is 'www.adverity.co', put value 'USA' in {New_field}, if the first 15 characters of the value from field {page} is 'pt.adverity.com', put a value 'POR' in {New_field}
Convertx: Modifying existing value based on the value from another field.
Field name: "country_code"
Python expression: dict([('United States','USA'),
('Portugal','POR')]).get({country})
=> If the value from field {country} is 'United States', replace the existing value from {country_code} with 'USA'; if the value from field {country} is 'Portugal', replace the existing value from {country_code} with 'POR'.
Addfieldx: In case there is no match
Field name: "New_field"
Python expression: dict([('sok','SOK'),
('cdp','CDP'),
({SLC},'Campaign')]).get({SLC})
=> Add "SOK" if the value of the field {SLC} is 'sok'; add "CDP" if the value of the field {SLC} is 'cdp', add "Campaign" for any other value in the field {SLC}.
Comments
0 comments
Article is closed for comments.