I am trying to run a Python code to fill blanks, separate cells etc on Python Script(lab) node. However, it is returning error with following message at the end.
TypeError: Rows can only be sliced by slice objects but got <class ‘type’>
I am a Python beginner, but after some Googling I am interpreting this message as “the data contains columns with data format “type” and that’s causing issues”. This is odd as all fields are either string or integer.
Does anybody know how should I deal with this error?
Please refer to the attached excel for the input data, Python script, and error message.
input and code.xlsx (35.8 KB)
Thank you for the assistance in advance!
I think the issue in your code starts here
title_dict_1 = df[~df['Type'].isna() & df['Column'].isna()][['Created date', 'Title','Question']]
Multiple filter criteria in a dataframe need to be put into paranthesis
@pt2501 I see several points.
One is that there seems to be a problem with the date and time conversion. The Python Labs node is struggling with that somewhat (Error with pandas in the Labs Python Integration - #9 by mlauber71). I imported the table first as PyArrow file and then converted specifically the Date columns to a pandas date time variable. It seems to work
table = knio.input_tables.to_pyarrow()
df = table.to_pandas(date_as_object=False)
df['Creation date'] = pd.to_datetime(df['Creation date'])
Then you append some data frames and so you will most likely produce double index entries which the conversion back to KNIME does not like (Error in Python script node - #6 by gonhaddock) - so:
would reset the index. To be honest the whole syntax seems quite messy and I had to remove a part in order to make it work so there is no guarantee that this will work but I think you have a framework of how to deal with this.
@carstenhaubold you might want to continue checking the arrow/pandas and date and timestamp issues between KNIME and Python (Labs).
kn_forum_46899_python_type_data.knwf (62.1 KB)
Thanks for the
pd.to_datetime workaround suggestion @mlauber71. Indeed, we still need to improve the date and timestamp issues. We have those issues scheduled to be tackled in the next weeks.
Thank you @Daniel_Weikert and @mlauber71 for answering!
The code @mlauber71 gave me went through with no errors. I really appreciate the help.
I will try to understand what has been done here so that I can resolve the issue myself at the next encounter.
Again, thanks awfully!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.