Help outputting integer column from Python node with input columns

Hello everybody,
I’m trying to add an integer column to the output of my Python Script node along with some input columns, but am having trouble with the output type.

My script contains a function that takes the input_table as a pandas data frame, and add some new columns from lists of integers as output_table. Finally the output_table is passed back to KNIME.
Unfortunately the output KNIME table contains the new columns as long datatype instead of integer.
Why this happens? Am I missing something? I’ve tried several methods to try to assure that the content of the list that is converted to the column are integers but the result it’s always the same: new columns of ‘long’ values data type.

Any help and suggestion is very welcome.

Here is a test snippet.

import as knio
import pandas as pd
input_table = knio.input_tables[0].to_pandas()

def myFunction(df):
    integer_list = list(range(len(df)))
    df['my_new_column'] = integer_list
    return df

output_table = myFunction(input_table)

knio.output_tables[0] = knio.Table.from_pandas(output_table)

Dear @gcincilla,

that is an issue due to how different OS treat integer columns in pandas.DataFrames. The troubleshoot section of our Python Integration guide has a link to this section, which should help you :slight_smile:

Tell me whether it worked!



Hi @steffen_KNIME,
Thank you very much for your suggestion! This actually solves the problem.
Adding the following 2 lines of code is sufficient to solve the above example:

import numpy as np
df['my_new_column'] = df['my_new_column'].astype(np.int32)



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