I have been working on just this the whole day but couldn't come up with better solution. I have list of dataframes
ls=[df1,df2,df3,df4] and tried several methods to merge.
df= reduce(lambda left,right: pd.merge(left,right,on='Time',how='outer'), ls)
Most of the examples I read just drop the col_y columns and change the col_x columns name. How can I achieve the desired dataframe, thanks in advance.
df1
Time col1 col2
1 a 11
2 b 12
3 c 13
4 d 14
df2
Time col3 col1
1 11 na
2 15 na
3 66 na
4 78 na
5 33 f
6 22 g
Mergd df3
Time col1_x col2 col3 col1_y
1 a 11 11 na
2 b 12 15 na
3 c 13 66 na
4 d 14 78 na
5 na na 33 f
6 na na 22 g
What I wanted the final df to be:
Desired merged df
Time col1 col2 col3
1 a 11 11
2 b 12 15
3 c 13 66
4 d 14 78
5 f na 33
6 g na 22