Python scripting node data input

I have a Knime Table Reader node connected to a Python Script node.
My python script is:
import knime.scripting.io as knio
dataset = knio
print('Shape of the dataset: ’ + str(dataset.shape))
print(dataset.head())

The system complains that there are no attributes for shape or head.
It appears that I am not specifying knio properly for Knime to pass the data set.
What am I doing wrong?

@Bob_Nisbet the in and out syntax would look like this for pandas dataframes.

import knime.scripting.io as knio

import numpy as np
import pandas as pd

# data from KNIME to Python (pandas)
df = knio.input_tables[0].to_pandas()

# data from python (pandas) to KNIME
knio.output_tables[0] = knio.Table.from_pandas(df) 

KNIME would work internally with Arrow format

https://docs.knime.com/latest/python_installation_guide/index.html#usage-examples

4 Likes

Hi @Bob_Nisbet,

mlaubers link to the documentation should answer these questions. It also shows the template section in the node from where you can get ready-to-use code snippets. Furthermore, please have a look at the description of the node.

Regards
Steffen

2 Likes

Thanks for the replies. My Python script works now.

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.