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:
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.