The Derive node modifies data values or creates new fields from one or more
existing fields. It creates fields of type formula, flag, nominal, state, count, and
conditional.
Example 1
Copy link to section
# Create and configure a Flag Derive field node
node = stream.create("derive", "My node")
node.setPropertyValue("new_name", "DrugX_Flag")
node.setPropertyValue("result_type", "Flag")
node.setPropertyValue("flag_true", "1")
node.setPropertyValue("flag_false", "0")
node.setPropertyValue("flag_expr", "'Drug' == \"drugX\"")
# Create and configure a Conditional Derive field node
node = stream.create("derive", "My node")
node.setPropertyValue("result_type", "Conditional")
node.setPropertyValue("cond_if_cond", "@OFFSET(\"Age\", 1) = \"Age\"")
node.setPropertyValue("cond_then_expr", "(@OFFSET(\"Age\", 1) = \"Age\" >< @INDEX")
node.setPropertyValue("cond_else_expr", "\"Age\"")
Copy to clipboardCopied to clipboard
Example 2
Copy link to section
This script assumes that there are two numeric columns called
XPos and YPos that represent the X and Y coordinates of a point
(for example, where an event took place). The script creates a Derive node that computes a
geospatial column from the X and Y coordinates representing that point in a specific coordinate
system:
stream = modeler.script.stream()
# Other stream configuration code
node = stream.createAt("derive", "Location", 192, 96)
node.setPropertyValue("new_name", "Location")
node.setPropertyValue("formula_expr", "['XPos', 'YPos']")
node.setPropertyValue("formula_type", "Geospatial")
# Now we have set the general measurement type, define the# specifics of the geospatial object
node.setPropertyValue("geo_type", "Point")
node.setPropertyValue("has_coordinate_system", True)
node.setPropertyValue("coordinate_system", "ETRS_1989_EPSG_Arctic_zone_5-47")
Copy to clipboardCopied to clipboard
Table 1. derivenode properties
derivenode properties
Data type
Property description
new_name
string
Name of new field.
mode
Single Multiple
Specifies single or multiple fields.
fields
list
Used in Multiple mode only to select multiple fields.
name_extension
string
Specifies the extension for the new field name(s).
add_as
SuffixPrefix
Adds the extension as a prefix (at the beginning) or as a suffix (at the end) of the field
name.
result_type
FormulaFlagSetStateCountConditional
The six types of new fields that you can create.
formula_expr
string
Expression for calculating a new field value in a Derive node.
flag_expr
string
flag_true
string
flag_false
string
set_default
string
set_value_cond
string
Structured to supply the condition associated with a given value.
state_on_val
string
Specifies the value for the new field when the On condition is met.
state_off_val
string
Specifies the value for the new field when the Off condition is met.
state_on_expression
string
state_off_expression
string
state_initial
On Off
Assigns each record of the new field an initial value of On or
Off. This value can change as each condition is met.
This property can be used to define the measurement associated with the derived field. The
setter function can be passed either a string or one of the MeasureType values. The
getter will always return on the MeasureType values.
For geospatial fields, this property defines the type of geospatial object represented by
this field. This should be consistent with the list depth of the values
has_coordinate_system
boolean
For geospatial fields, this property defines whether this field has a coordinate
system
coordinate_system
string
For geospatial fields, this property defines the coordinate system for this field
About cookies on this siteOur websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising.For more information, please review your cookie preferences options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.