-1

I have 2 dataframes.

One is

DF1

col1 col2 label a qq 1 a ww 1 a ee 0 b qq 1 b ww 0 b rr 0 

Another one is

DF2

col1 col2 label a qq a ww a ee b qq b tt b rr 

So if there is matching pair with col1 and col2, I want to write label of DF1 to DF2 label. And if there is no matching pair, I want to just mark 0 to DF2 label.

How can i deal with this.

Thanks in advance.

0

1 Answer 1

1

Could you please try following.

df2['label']=np.where(df2['label'].isna(),df1['label'],df2['label']) 

Once we print edited df2 its values will be as follows now.

 col1 col2 label 0 a qq 1.0 1 a ww 1.0 2 a ee 0.0 3 b qq 1.0 4 b tt 0.0 5 b rr 0.0 
Sign up to request clarification or add additional context in comments.

2 Comments

it says operands could not be broadcast together with shapes (2435,) (2435,) (8828,)
@puhuk, not sure but for your given samples it worked fine. I created 2 df from your provided samples and ran above code which executed from me for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.