Skip to content
Advertisement

Create a new column in a dataframe containing string values from different columns based on values in another column of a dataframe

JavaScript

I would like to add string Null at the end if conversion is 0 and add conversion column value if conversion value is 1 .

`I have a below error

TypeError: Cannot broadcast np.ndarray with operand of type <class ‘list’>

Advertisement

Answer

If you have dataframe like this:

JavaScript

Then this will create new “path” column:

JavaScript

Prints:

JavaScript

EDIT: To append to a list in column “channel”:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement