Trouble with generating output table from a python script node

Hi all,
I am a novice at Python. If someone can help me out with this issue, that would be great! What I am trying to do here is create a new column based on an existing column.

Following is the script for the same -

import pandas as pd

#new column
df = pd.DataFrame(data=input_table_1)
new_col = df[‘conv’]

#insert the new column at position 2
df = df.insert(2, ‘new_col’, new_col)

output_table_1 = df.copy()

And following is the error I have been getting -

Traceback (most recent call last):
File “”, line 11, in
AttributeError: ‘NoneType’ object has no attribute ‘copy’

Are the output/input tables NoneType objects? I have referred to material and solutions from this forum wherein the usage of copy function to write the table in the output has worked. I do not understand what is going wrong in this case.

If you look at the results of your code line by line, you’ll see the problem

When I execute your line df = df.insert(2, 'new_col', new_col) I get an object called ‘df’ with a type of NoneType and a value of None. This cannot be copied.

I think your syntax for this function is off. Changing the line to simply df.insert(2, "new_col", new_col), allows it to execute without any problems on my end.


Thank you for your quick response elsamuel. That was super helpful!

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