Custom Code vs Quick Columns (with Operation 'Custom Code')

Modified on Wed, 15 Mar, 2023 at 10:08 AM

Custom Code 

The Custom Code  function is typically used when you need many lines of code to transform your data. These can be 10-20 lines long for example, to transform the entire dataset in a specific and custom way. You are not limited to adding new columns, you can do other manipulations. You have the option to rename the resulting dataset, so that you do not overwrite the input dataset. You can add a descriptor to the step so that when you click apply there is a message displayed in the notebook summarising what the custom code block performs.

Here is an example of how to creating a column ratio and then only selecting rows for which ratio > 10:

df['ratio'] = df['lift']/df['drag']
df = df[(df['ratio'] > 10)]

Notice that you have to reassign column changes to a column in the dataframe explicitly. Also, you have to reassign changes to the dataframe back to the variable df which holds the dataframe. Otherwise the changes would not become effective.

Quick Columns

The Quick Columns function using the Operation "Custom code" uses custom code to determine the values for your new column in the input dataset. This can be multiple lines of custom code but it's typically only one line. As you note in the example below you do not need to assign the result of your calculation/transformation to a dataframe column explicitly. This will be done by the function internally. The result of your code will be assigned to the dataframe column which you specified in the field Name.

If you need more than one line of code you have to include a return statement in the line of code which returns the final desired result.

Here is an example of how to create the same column ratio as above:

df['lift']/df['drag']

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article