I have this code which can be executed successfully in a Python Script 1=1 node inside the configuration window
-------------------------------------------------------------
import numpy as np
import pandas as pd
data = input_table.copy()
dataframe = pd.DataFrame(data)
datacols = list(dataframe)
substring = '+'
Value_Cols =[s for s in datacols if substring in s]
no_plus = Value_Cols[1].split('+')
Pivot_Value = [no_plus[-1]]
Pivot_Cols = no_plus[0].split('_')
Col_Fields = Pivot_Cols+Pivot_Value
#GUI PART##
#Select the items from your list
#Select the items from your list
import tkinter as tk
from tkinter import*
#from PIL import ImageTk, Image
Final_Arrange_Cols =[]
Final_Order_Cols = []
root=tk.Tk()
#set title of GUI
Label(root,text="SET YOUR COLUMN NAME BY CLICKING THE SEQUENCE OF THE STRINGS",font=("Helvetica", 10)).place(x=60, y=0)
Label(root,text="Original Sequence",font=("Helvetica", 10)).place(x=60, y=50)
Label(root,text="Chosen Sequence",font=("Helvetica", 10)).place(x=400, y=50)
Label(root,text="ver 01 otaag abs(cdp)",font=("Helvetica", 8)).place(x=450, y=380)
sizex = 600
sizey = 400
posx = 40
posy = 20
root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
#itemsforlistbox=['one','two','three','four','five','six','seven']
def CurSelect(evt):
value=str(mylistbox.get(mylistbox.curselection()))
value_list =[]
value_list.append(value)
for item in value_list:
mylistbox2.insert(tk.END,item)
Final_Arrange_Cols.append(value)
Final_Order_Cols.append(Col_Fields.index(value))
Label(root,text="Your Final Column Name Format : "+ str("_".join(Final_Arrange_Cols)),font=("Helvetica", 10)).place(x=60, y=300)
#first listbox
mylistbox=Listbox(root,width=30,height=10,font=('times',13))
mylistbox.bind('<<ListboxSelect>>',CurSelect)
mylistbox.place(x=32,y=90)
#2nd listbox
mylistbox2=Listbox(root,width=30,height=10,font=('times',13))
mylistbox2.bind('<<ListboxSelect>>',CurSelect)
mylistbox2.place(x=350,y=90)
button = Button (root, text = "SEND SEQUENCE", command = root.destroy).place(x=250, y=350)
#button.pack()
for items in Col_Fields:
mylistbox.insert(END,items)
root.mainloop()
#print(Final_Arrange_Cols)
Final_Col_Format ="_".join(Final_Arrange_Cols)
#LOOP TO GET THE DESIRED FORMAT OF COLUMN
#print(Value_Cols)
#KNIME needs unique column names, method proposed for generating unique column names
Total_Col_Names=[]
for elem in Value_Cols:
parts = Col_Fields
repart = []
for idx in Final_Order_Cols:
repart.append(parts[idx])
remaining = set(range(len(parts)))
remaining = [x for x in remaining if x not in Final_Order_Cols]
for idx in remaining:
repart.append(parts[idx])
Total_Col_Names.append('_'.join(repart))
#End proposed method
#This line fixes the indexing issues encountered since dataframes coming from KNIME have string indices per default
dataframe.set_index(pd.Index(range(len(dataframe))), inplace=True)
#Fixed
df_values = dataframe.loc[0:,Value_Cols]
df_values.columns =Total_Col_Names
Pivot_Index = list(set(datacols).difference(Value_Cols))
df_index = dataframe.loc[0:,Pivot_Index].astype('str')
Final_Table = pd.concat([df_index,df_values],axis=1)
output_table = Final_Table
-----------------------------------------------------------------------------------
But when I execute it as a node, it has the following error:
ERROR Python Script (1⇒1) (Labs) 0:16 Execute failed: An exception occured while running the python kernel.
ERROR PythonKernel AttributeError: 'DataFrame' object has no attribute 'dtype'
What could be the cause of this error?
When I run it in another IDE like jupyter, it works fine.
Sample input table attached