The following node is available in the Open Source KNIME predictive analytics and data mining platform version 2.7.1. Discover over 1000 other nodes, as well as enterprise functionality at
http://knime.com.
JPython Script 1:1
Executes a JPython script, taking 1 input DataTable and returning 1 output DataTable.
A simple example script is included (but commented out) in the dialog's text window of the Script tab.
Currently employs jython v2.2.1.
Dialog Options
- Append columns to input table spec
-
If checked, the columns as given in the list are appended to the
input table specification, i.e. the number of columns in the output table
equals the number of input columns plus the number of columns as given in the list.
If unchecked, the output table will have as many columns as given in the list.
- Column list
-
Specify the column name and type of all result columns. After adding a
new column, click on the name or type to change its value.
- inData0
-
The input DataTable containing all available input from input port 0.
Available methods: getDataTableSpec(), iterator().
Example use to obtain DataTableSpec:
dts = inData0.getDataTableSpec()
input1ColumnIndex= dts.findColumnIndex("H atoms")
Example use to step through rows in DataTable:
iterator = inData0.iterator()
while iterator.hasNext():
row = iterator.next()
...
- outContainer
-
Output container housing the outgoing DataTable for output port 0. This must be populated with rows by the script or else there will be no output from the node.
Available methods: addRowToTable(ColumnRow arg1)
Example use to iteratively create outgoing DataTable (creates duplicate of input DataTable):
iterator = inData0.iterator()
while iterator.hasNext():
row = iterator.next()
outContainer.addRowToTable(row)
- ColumnIndex
-
ColumnIndex objects point to particular columns in the DataTable. A ColumnIndex is useful as input to other methods which need to access values in one particular column of the DataTable.
Available methods: NONE
Example use to identify the column that is labelled "Size of Shoe":
dts = inData0.getDataTableSpec()
shoeSizeColumnIndex= dts.findColumnIndex("Size of Shoe")
- ColumnRow
-
ColumnRow objects correspond to rows in the DataTable. The results from methods that return a row from a DataTable are actually returning an object of this class.
Available methods: getCell(ColumnIndex arg1)
Example use to obtain the value from a row for a column that contains strings:
dts = inData0.getDataTableSpec()
petNamesColumnIndex= dts.findColumnIndex("Name of Pet")
iterator = inData0.iterator()
row = iterator.next()
current_name = str(row.getCell(petNamesColumnIndex))
Example use to obtain the floating-point value from a row for a particular column:
dts = inData0.getDataTableSpec()
petWeightColumnIndex= dts.findColumnIndex("Weight of Pet")
iterator = inData0.iterator()
row = iterator.next()
current_name = float(str(row.getCell(petWeightColumnIndex)))
- DataTableSpec
-
DataTableSpec objects contain specifications of all of the types of data currently in the DataTable.
Available methods: findColumnIndex(String arg1)
Example use to obtain DataTableSpec and then locate a particular column by its label:
dts = inData0.getDataTableSpec()
sunshineColumnIndex= dts.findColumnIndex("Days of Sunshine")
Ports
Input Ports
0 |
Table that the JPython script will operate on. |
Output Ports
0 |
Table containing the results of the JPython script. |
This node is contained in KNIME JPython Scripting nodes
provided by KNIME GmbH, Konstanz, Germany.