I am getting “TypeError: 'DataFrame' object is not callable” when I'm trying to iterate over a pandas Dataframe in a Knime python script node

Basically I am tyring to iterate over rows in a pandas data frame. This data frame was automatically created in Knime through a python script node.
The name of the data frame is “input_table”.

The dataframe has three columns: Location, URL and Document.

I am gettin this error: TypeError: ‘DataFrame’ object is not callable, when I am trying to loop over rows.

I already looked for similiar problems, but none of the solutions worked for me. This is the code I am using, since the data frame was created automatically.

for index, row in input_table():

   print(row["Document"])
1 Like

Hi @gnime

Try:

for index, row in input_table.iterrows():
print(row[“Document”])

hope this helps.

gr. Hans

1 Like

Hi Hans,

Thanks for your answer.

When I am tyring this I am getting the error:

ERROR Python Script (1⇒1) 0:13 Execute failed: An exception occured while running the Python kernel. See log for details.

1 Like

Hi @gnime

It works on my machine :upside_down_face: see iterate_row_pythonnode.knwf (12.2 KB)

Maybe this post Python code is successful in the config window but fails when the node is executed helps you out?

gr , Hans

1 Like

Hi Hans,

Thanks I will look into it.
Maybe some additional info:

I am getting the Data from a Database reader.
The target column Database table I am reading from hast 33.000 rows.

The target column “Document” contains the text of .html files in text format.

Hi @gnime,

I created a simple example WF. python_iterate_data_frame.knwf (6.1 KB)
The source of the data should not matter. Are you able to execute any other Python Scrip node? Maybe it is a general problem with your setup. If the attached WF doesn’t work for you, it would be great if you could attach the KNIME log file to your next post.

Hope that helps.

Cheers,
David

4 Likes

Hi Dave,

Thanks for your answer.

My script works now, I just forgot to define an output table.
My problem now is that my code works with a small sample (1400 rows), but does not work with with my full dataset of 33.000 rows.

I am getting the error:

ERROR Python Script (1⇒1) 0:13 Execute failed: An exception occured while running the Python kernel. See log for details.

Could you maybe attach the log file?

Hi Dave,

I copied the log at the moment the error occured.
I hope it helps.

error.txt (78.2 KB)

Hi @gnime,

you seem to be running out of memory Caused by: java.lang.OutOfMemoryError: Java heap space. See here to increase the memory KNIME can use. I hope that fixes the error.

Cheers,
David

5 Likes

Worked like a charm!

Thanks Dave

1 Like

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