'Pandas Merge Dataframes [duplicate]

I have some problem about Pandas.

I have

   df1 = pd.DataFrame({'col1': ['t1' ,'t2','t3','t4','t5'],
            'col2': ['1' ,'2','3','5','6']})

   df2 = pd.DataFrame({'col1': ['t1' ,'t2','t4','t5'],
            'col2': ['5' ,'7','8','2']})

   df3 = pd.DataFrame({'col1': ['t1' ,'t2','t4','t5','t6','t7'],
            'col2': ['6' ,'3','2','5','3','12']})

and result is

   t   d1  d2  d3

   t1   1  5   6
   t2   2  7   3
   t3   3  0   0
   t4   5  8   2
   t5   6  2   5
   t6   0  0   3
   t7   0  0   12

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source