Skip to content

Convert data tables

Transfer data between KNIME tables and Python structures using the knime.scripting.io (knio) module.

Pandas

Pandas is the standard library for data manipulation in Python. Use these methods to work with pd.DataFrame objects.

To convert an input table to a Pandas DataFrame:

python
import knime.scripting.io as knio
df = knio.input_tables[0].to_pandas()

To write a Pandas DataFrame to a KNIME output port:

python
import knime.scripting.io as knio
# Assuming 'df' is your existing Pandas DataFrame
knio.output_tables[0] = knio.Table.from_pandas(df)

PyArrow

Apache Arrow provides high-performance, columnar data structures. Use these methods to work with pa.Table objects, which is recommended for larger datasets.

To convert an input table to a PyArrow Table:

python
import knime.scripting.io as knio
table = knio.input_tables[0].to_pyarrow()

To write a PyArrow Table to a KNIME output port:

python
import knime.scripting.io as knio
# Assuming 'table' is your existing PyArrow table
knio.output_tables[0] = knio.Table.from_pyarrow(table)

INFO

The knime package required for these conversions is provided automatically by the default bundled Python environment (see Bundled Packages). Do not install a package named knime via pip in your environment, as this will cause a name clash and script failure.