Given the following three Pandas data frames, I need to merge them similar to an SQL full outer join. Note that the key is multi-index type_N
and id_N
with N
= 1,2,3:
import pandas as pdraw_data = {'type_1': [0, 1, 1,1],'id_1': ['3', '4', '5','5'],'name_1': ['Alex', 'Amy', 'Allen', 'Jane']}
df_a = pd.DataFrame(raw_data, columns = ['type_1', 'id_1', 'name_1' ])raw_datab = {'type_2': [1, 1, 1, 0],'id_2': ['4', '5', '5', '7'],'name_2': ['Bill', 'Brian', 'Joe', 'Bryce']}
df_b = pd.DataFrame(raw_datab, columns = ['type_2', 'id_2', 'name_2'])raw_datac = {'type_3': [1, 0],'id_3': ['4', '7'],'name_3': ['School', 'White']}
df_c = pd.DataFrame(raw_datac, columns = ['type_3', 'id_3', 'name_3'])
The expected result should be:
type_1 id_1 name_1 type_2 id_2 name_2 type_3 id_3 name_3
0 3 Alex NaN NaN NaN NaN NaN NaN
1 4 Amy 1 4 Bill 1 4 School
1 5 Allen 1 5 Brian NaN NaN NaN
1 5 Allen 1 5 Joe NaN NaN NaN
1 5 Jane 1 5 Brian NaN NaN NaN
1 5 Jane 1 5 Joe NaN NaN NaN
NaN NaN NaN 0 7 Bryce 0 7 White
How can this be achieved in Pandas?