Replace with Dictionary
This transform replaces values of a given column with the values passed in the dictionary. This has key-value pair where key is an existing value in the column and value is the new value with which the existing value must be replaced.
tags: [“Data Preparation”]
Parameters
The table gives a brief description about each parameter in Replace with Dictionary transform.
- Name:
By default, the transform name is populated. You can also add a custom name for the transform.
- Input Dataset:
The file name of the input dataset. You can select the dataset that was uploaded from the drop-down list. (Required: True, Multiple: False)
- Output Dataset:
The file name with which the output dataset is created after replacing with values passed in the dictionary. (Required: True, Multiple: False)
- Replace dictionary:
The dictionary (key-value pair) to remap the column values. (Required: True, Multiple: False, Datatypes: [“STRING”])
- Column:
The name of the column in which values must be replaced. (Required: True, Multiple: False, Datatypes: [“STRING”], Options: [‘FIELDS’], Datasets: [‘df’])
The sample input for this transform looks as shown in the screenshot:
The output after running the Replace with Dictionary transform on the dataset appears as below:
How to use it in Notebook
The following is the code snippet you must use in the Jupyter Notebook editor to run the Replace with Dictionary transform:
template=TemplateV2.get_template_by('Replace with Dictionary')
recipe_Replace_with_Dictionary= project.addRecipe([car_data, employee_data, temperature_data, only_numeric], name='Replace with Dictionary')
transform=Transform()
transform.templateId = template.id
transform.name='Replace with Dictionary'
transform.variables = {
'input_dataset':'car',
'output_dataset':'Replaced',
'dic':"{'two':'t'}",
'col':"doornumber"}
recipe_Replace_with_Dictionary.add_transform(transform)
recipe_Replace_with_Dictionary.run()
Requirements
pandas