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)
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
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
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:
df7.reset_index(inplace=True)
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).
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.