Skip to content
Advertisement

create new column on conditions python

I have a ref table df_ref like this:

JavaScript

I need to create a new column in another table based on ref table.The table like this:

JavaScript

The output table df_org looks like:

JavaScript

If any column value in col1 and col2 can find in ref table, it will use the ref col in ref table. If col1 and col2 are NULL, So they cannot find anything in ref table, just return NULL. I use this code, but it doesn’t work.

JavaScript

ValueError: operands could not be broadcast together with shapes

Advertisement

Answer

You want to perform two merges and combine them:

JavaScript

output:

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