how to use python script?

Hello everyone!

I have a question related to a Python script node. I want to use this node to divide a list of Excel files with an equal number of rows into separate groups. I have already found a solution in Jupyter Notebook, but it’s quite challenging to implement it in KNIME. I’ve installed Miniconda and set up the basic parameters, but I’m unsure how to proceed with the output. Can anyone help me with this? I really appreciate it. Thank you very much.

Hello @quangdatitc
I’ve replied a post just yesterday, for a similar request.

The basics are about how to control input data and output data. You can play with multiple outputs by adding output ports as in the image.

You can make work your Jupyter Notebook code, by fitting it into the ‘# Things happen’ section of code.

I hope this helps to answer your question.

BR

1 Like

Thank you for taking the time to guide me!
but my output like list() ex:df=[[1,3,4],[2,61,1]]
so what should i do?

Hello @quangdatitc
Take a look into this post:

import knime.scripting.io as knio
import pandas as pd
knio.output_tables[0] = knio.Table.from_pandas(
    pd.DataFrame(
        [[1,3,4],[2,61,1]], columns=['column01', 'column02', 'column03']
    )
)

You can also remove input port, and use Python Script node as a source; importing or creating your own data in the code.

BR

2 Likes

Hi @gonhaddock
Thanks for giving me advice.I also found another method through an article

1 Like

@quangdatitc please note some syntax has changed. Take a look at these examples:

2 Likes

Hi @mlauber71
thanks you so much!

1 Like

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