-
Notifications
You must be signed in to change notification settings - Fork 195
Transforming Data
Karma offers to commands to transform the values in cells to create new columns.
-
PyTransform
allows you to type expressions in Python to define data transformations -
Transform
allows you to define the tranformations by providing examples.
You invoke both commands from the menu of commands available on all columns:
##Transformations Using Python
The screenshot below illustrates the use of the PyTransform
command.
Suppose you want to transform the Measurements
column to extract the measurements of artwork frames. These are the parts of the string following the letter f
(e.g., f 14 1/2 x 32 1/4
).
You select PyTransform
in the menu of the Measurements
column, and Karma shows you the following dialogue where you specify how to perform the transformation:
The main part of the dialogue is the area where you enter your Python code.
Here you enter code that specifies how to compute the value of a cell in the new column as a function of the values of the cells in the same row.
Using the getValue
function you can access the value of any cell in a row.
For example getValue("Measurements")
gets the value of the cell in the Measurements
column.
The sample code in the screenshot above shows how to find the index of the string f
and then extract all characters from that index to the end of the string.
You can test your code by clicking on the Preview Results for Top 5 Rows
button.
If your code has errors, you can click on the View Errors
button to see the errors that the Python interpreter generates for the top 5 rows.
You can access the values of cells in all columns by calling getValue
using the name of the column.
For example, you can easily combine the values of two columns, e.g., first
and last
to create a new column name
using the code return getValue("first")+" "+getValue("last")
.
###Hierarchical Sources (e.g., XML or JSON)
##Transformations Using Examples