Help to use Python do insert variable in SQL code

I turned an array into a string. But I need to take this string to the next node in order to use it in a SQL. Any tips on how to do this?

I want to use this string like I’m doing with Period1. Instead of typing, use a list that’s in a file that I’m going to read.

If there is another simpler way to do it, let me know.

@Aldemir you can export data from within the Python node as Flow Variables or as a dataframe (from a pandas dataframe). The code would look something like this:

import knime.scripting.io as knio
import numpy as np
import pandas as pd

# bring your string to a Flow Variable
knio.flow_variables['var_txt_cbi'] = txt_cbi

# bring your content to a pandas data frame
output_table = pd.DataFrame({'column_txt_cbi':    [txt_cbi]})

# bring the dataframe back to KNIME
knio.output_tables[0] = knio.Table.from_pandas(output_table)

Question is would you need Python for what you want to do or are there KNIME nodes that also can do the transformation you want. In any case if you want to use more KNIME and Python it might be good to take a look at the relevant guides. Also I would recommend this sample workflow that presents examples for things you can do with KNIME and Python:

Also there is a Space on the KNIME hub with some more examples how to use KNIME and Python:


Data Transfer between KNIME & Python Just Got Faster

KNIME Python Integration Guide
https://docs.knime.com/latest/python_installation_guide/#_introduction

3 Likes

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