Hi @fbagirov,
I am afraid this will not work the way you would like it to, given how our Jupyter integration is currently designed.
knime_jupyter.load_notebook
loads the Jupyter notebook into the node’s “main” Python script as a separate Python module (comparable to what Python’s import
statement does). In Python, the namespaces/scopes of the variables of two different modules are isolated from one another, that is, code inside the notebook cannot simply reference variables declared in the node’s main Python script. So some mechanism will be necessary to explicitly pass the required variables from the main script to the notebook. Right now, this is only possible by means of function calls (like the one in line 30 in your screenshot, where ìnput_table
is explicitly being passed to my_notebook.sum_each_row
). So the only solution that comes to mind would be to remodel your notebook such that all cells that require external input become functions:
def calculate_centroid(df):
df['the_geom'] = df['the_geom'].apply(wkt.loads)
Come to think of it, it would be really cool to be able to do something like this:
notebook = knime_jupyter.load_notebook(notebook_directory, notebook_name, vars={'df' : df})
Would that be interesting for you? Then I would create a feature request for that (or some comparable mechanism).
Marcel