2. Simplificando los filtros y la adición de columnas
Simplifying Filters and Column Addition
In this section, we will simplify the process of applying filters and adding columns with the values "green, red, yellow":
We can either remove the Filter and AddColumns steps before adding the new boxes or delete them afterward, depending on our preference.
The idea is to replace each Filter+AddColumn transformation set with a single DataWrangler step.
To do this, we add a new DataWrangler step and connect its left input to the JoinDB step (where data initially flowed into the first filter) and its right output to the Union step. We name this box RiesgoRojo.
In this transformation step, we will first apply the filter and then add the column containing the "Rojo" label. Since we want to apply these transformations to the entire dataset, we do not need to select a specific column. DataWrangler allows us to perform actions like Filter (funnel icon at the top) and AddColumn (plus icon) without selecting a column:
First, we add the filter, which prompts us with a configuration form:
We need to define a condition for the filter. In our case, the condition for the "Rojo" label is:
LegalCase = 1 OR PoliceReport = 1
We configure it accordingly:
Upon applying it, we can see that only the rows meeting this condition are selected (you may need to scroll right in the data table to verify):
Next, we add the column with the label "Rojo" by clicking the plus icon. A form appears where we provide:
The expression (in this case, the column value 'Rojo') and an alias (column name, which will be Riesgo):
Once applied, the new column appears in the table (at the far right):
Remember that you can delete or edit transformations from the right-hand menu:
Next, we add two more DataWrangler transformations for the "Amarillo" and "Verde" labels, using the following conditions:
Amarillo:
(LegalCase=0 AND PoliceReport=0) AND (ContactAudit = 1 OR FraudSuspicion = 1)
(LegalCase=0 AND PoliceReport=0 AND ContactAudit = 0 AND FraudSuspicion = 0) AND Credit_amount <= 4000
After completing these steps, the final structure should look like this:
Everything should now function correctly, just as it did before making these modifications.