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!
df1.merge(df2, on='col1', how='outer').merge(df3, how='outer').fillna(0).rename(columns={'col2_x': 'd1', 'col2_y': 'd2', 'col2': 'd3'})