1

I have a dataframe looks like:

    x   y   z
1   3   7   1
2   7   5   2
3   8   2   3

and other dataframe looks like:

    x   y   z
1   7   5   4
2   8   2   8
3   4   5   5
4   7   3   7
5   9   5   3
6   3   7   9

Now I want to merge the two frames, and the frame after merge to be looked like this:

    x   y   z
1   3   7   1
2   7   5   2
3   8   2   3
4   4   5   5
5   7   3   7
6   9   5   3

2 Answers 2

4

Use concat + drop_duplicates with define columns for check duplicates x and y + reset_index for remove duplicated index values:

df = pd.concat([df1,df2]).drop_duplicates(['x','y']).reset_index(drop=True)
print (df)
   x  y  z
0  3  7  1
1  7  5  2
2  8  2  3
3  4  5  5
4  7  3  7
5  9  5  3
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @jezrael, that is what i was wanted.
2

Concatenate, then dedupe

pandas.concat([df1,df2]).drop_duplicates().reset_index(drop=True)

1 Comment

yes it add all value to the dataframe did not remove duplicates on x and y

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.