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

Merge two different lenght dataframes with one column with some duplicate value

I have two dataframes:

df:

    A   B
0   1   3
1   2   4

df2:

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

    A   C
0   1   5
1   2   6
2   3   7

and I want to merge in a way that the column ‘A’ add the different values between DataFrames but merge the duplicates.

Desired output:

    A   B   C
0   1   3   5
1   2   4   6
2   3   nan 7

>Solution :

You can use combine_first:

df2 = df2.combine_first(df)

Output:

   A    B  C
0  1  3.0  5
1  2  4.0  6
2  3  NaN  7
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