Python Script node - how do I output a single string value?

Hi, I can’t find a way to get a very simple piece of Python code to work for me in the Python Script node. I’ve tried lots of approaches, all of which work fine in Spyder IDE, but get rejected by Knime’s "output _table_1 = ". I know it requires a dataframe but everything I’ve tried generates an error.

The workflow is: “table creator” to “python script”. Required output from python script is a single value which gets used in other workflows.

As simple example

  1. Table image:

  2. Python Script:
    import pandas as pd
    ds = pd.DataFrame(input_table_1.copy())
    ds1 = ds.loc[“Row1”,“Series”] ###output from this is str “S1”

ser = ds1.??? to be accepted as dataframe by Knime

output_table_1 = ser

A broader question: is there some way of finding out the limitations of Python in Knime scripts. That’s not meant as a criticism, simply to save me tearing out what’s left of my hair:-)

Any (polite) suggestions welcome

Hello @nojrebrab

Your output is mandatory to be a pd.DataFrame object; then the following code should do the job:

import pandas as pd
ds = pd.DataFrame(input_table_1.copy())
ds1 = ds.iloc[1:2,2]
output_table_1 = pd.DataFrame(ds1.copy())



Great, that works. I thought I’d tried most permutations but not this one. Many thanks.


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