Apply Function

General information

Brick provides a possibility to create new features by applying a function to a column or two columns.

Description

Brick Location

Bricks Data Manipulation → Transform Apply Function

Brick Parameters

  • Setting
    • One of the options available in the drop-down menu: 'Apply function to a column', 'Apply a function to two columns'.
  • Column1
    • List of possible columns for selection. This field is obligatory for any setting selected.
  • Column2
    • List of possible columns for selection. This field is obligatory for setting = 'Apply function to two columns' only.
  • Function
    • List of possible functions to apply. This field is obligatory for any setting selected.
  • Value1
    • Text input field. Additional parameter required for functions: round, quantile, add, subtract, multiply, divide and power in case of setting= 'Apply function to two columns' and for functions: replace part of the text and replace part of the text in case of setting = 'Apply a function to two columns'.
  • Value2
    • Text input field. Additional parameter required for functions: replace part of the text and replace part of the text in case of setting = 'Apply function to a column'.
  • Separator
    • Text input field. Additional parameter required only for a function concatenate in case of setting = 'Apply a function to two columns'.
  • New Column Name
    • Input field. This field is obligatory for any setting and function selected. Please, note, that you may specify the existing column as an output one, in this case, its values will be overwritten.
       

Brick Inputs/Outputs

  • Inputs
    • Brick takes the dataset.
  • Outputs
    • Brick produces the result as an extended input dataset with one additional column called as specified in the parameter "New Column Name".

Description

You should use this brick when there is a need to create an additional column. There are several options available on how a new column is going to be created.

Example of usage

You should select one setting from the drop-down brick menu, column or columns and a function that should be applied. The result produced by the applying selected function to the column/columns would be added as a new column to the output dataset. The following options are available:

Apply a function to a column

notion image
Mandatory inputs:
  1. Column from the input data
  1. One function from the following:
      • min, max, mean, mode, median, sum, count works only with numeric data types, no additional parameters are needed, produces one unique value.
        • Example: max function applied to the column Age(data 1)
          notion image
      • abs, calculate log, calculate exp works only with numeric data types, no additional parameters are needed, produces result row by row.
        • Example: calculate exp function applied to the column PassengerId:
          notion image
      • quantile, round, power works only with numeric data types, additional parameter Value is required in this case, produces one unique value.
        • Example: 0.5 quantile Age (data1)
          notion image
      • add, subtract, multiply, divide, power works only with numeric data types, additional parameter Value is required in this case, produces result row by row.
        • Example: max Age(data1)
          notion image
           
      • replace the value additional numeric inputs Value1 and Value2 are needed, replaces Value1 in the input column with Value2.
        • Example: replaced the value of 35 in the column Age(data1) with 100
          notion image
      • replace part of the text works only with string data types, additional inputs Value1 and Value2 are needed, replaces all matches of Value1 in the input column with Value2.
        • Example: replaced part of the text that matched "James" in column Name(data1) with "Datrics"
          notion image
           
  1. New column name
    1. Column name to be added to the dataset (any existing column name can be used, in this case, data in this column would be overwritten with the new one).

Apply a function to two columns

Mandatory inputs:
  1. Column1 and Column2 from the input data
  1. Function from the drop-down menu
  • add, subtract, multiply, divide, power works only with numeric data types, no additional parameters are needed, produces result row by row.
    • Example: add Fare(data1) and Age(data 1)
      notion image
  • concatenate works only with string data types, additional text input Separator is needed (default '_'), concatenates to strings into one using the specified separator.
    • Example: concatenated Sex(data1) and Cabin(data1)
      notion image
       
  • replace the value additional numeric input Value and is needed, replaces Value in the input column with the respective value from column2.
    • Example: replace the value 26 in column Age with the value from column Fare
      notion image
  • replace part of the text works only with string data types, additional inputs Value is needed, replaces all matches of Value in the input column1 with the respective value from column2.
    • Example: replaced part of the text that matched "85" in column Cabin(data1) the respective value from Ticket(data1).
      notion image
       
3. New column name
Column name to be added to the dataset (any existing column name can be used, in this case, data in this column would be overwritten with the new one).