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

Concatenate two df with same kind of index

I have two df.

df1:

         date   a
0   2021-12-15  0.16
1   2021-12-16  0.16
2   2021-12-17  0.16

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

         date   b
0   2021-12-16  0.17
1   2021-12-17  0.17
2   2021-12-18  0.17

I want this df as output

         date   a    b
0   2021-12-15  0.16 NaN
0   2021-12-16  0.16 0.17
1   2021-12-17  0.16 0.17
2   2021-12-18  NaN  0.17

I’m trying to use both concat pd.concat([df1,df2],axis=1 and merge df1.merge(df2,on=['date'] but I’m not able to find a solution

>Solution :

Have a look at pandas merge function.

You want to do:

pd.merge(df1, df2, on='date', how='outer')

This link explains well the different types of merge possible.

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