Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to merge dataframes where a value is not matching in other column

I have huge data and I want merge it on a specific column where values from df1 is not available in df2 and vice versa.

Example:

df1:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Domain        Sales
google.com    100
facebook.com  200
youtube.com   300

df2:

Domain       Sales
google.com   100
yahoo.com    200
youtube.com  300

Required output:

Domain          Sales
facebook.com    200
yahoo.com       200

I have tried:

df = pd.merge(df1, df2, on="Domain", how="outer")

and all the other values for the how parameter, but it does not give me the required output. How can I achieve the required output?

>Solution :

pd.concat([df1, df2]).drop_duplicates('Domain', keep=False)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading