In DataPrep
Enrich your data by inserting new calculated fields using our advanced scripting editor with autocomplete.
Enrich your data by inserting new calculated fields using our advanced scripting editor with autocomplete.
In DataPrep, you can create custom calculated columns based on existing data.
For example, you might have a dataset with "Sales" and "Expenses" columns and want to calculate the "Profit" as a new column:
You can add a new column 'profit' and then write the following script:
Here, the calculated column "Profit" is derived by subtracting the "Expenses" column from the "Sales" column.
Example 1: Concatenate First and Last Name in New Column
Description: This script concatenates the "First Name" and "Last Name" columns and returns a single string containing both names in a new column 'Full Name'.
Code:
Example 2: Create a New LocalDateTime Column
Description: This script parses the string values in the "Order Date" column, assuming they are in the format "yyyy-MM-dd HH:mm:ss," and converts them into LocalDateTime objects in a new column.
Code:
Example 3: Create a New Column with the Quarter for the "Order Date"
Description: This script determines the quarter for the "Order Date" based on the month and creates a new column with the quarter information.
Code:
Example 4: Reformat a Date String
Description: In this example, you have retrieved data with a date in a less user-friendly format, such as "2023-10-25T12:22:05.2247439Z." To improve data management and enhance readability, you will reformat the date information and introduce a new 'date' column.
Code: