I have 3 data frames that looks like this:
In [1]: import pandas as pd
In [26]: d1 = {'foo':0.3, 'bar':0.55}
In [27]: d2 = {'foo':0.4, 'bar':0.55, 'qux':0.3}
In [28]: d3 = {'foo':0.1, 'qux':5.55}
In [29]: df1 = pd.DataFrame.from_dict(d1, orient='index')
In [31]: df2 = pd.DataFrame.from_dict(d2, orient='index')
In [32]: df3 = pd.DataFrame.from_dict(d3, orient='index')
In [43]: df1.columns = ['x']
In [45]: df2.columns = ['y']
In [46]: df3.columns = ['z']
In [50]: df1
Out[50]:
x
foo 0.30
bar 0.55
In [51]: df2
Out[51]:
y
qux 0.30
foo 0.30
bar 0.55
In [52]: df3
Out[52]:
z
qux 5.55
foo 0.30
What I want to do is to merge them and create single big data frame that looks like this:
x y z
foo 0.3 0.4 0.1
qux NA 0.3 5.55
bar 0.55 0.55 NA
How can I achieve that?
I tried this but failed:
dfs = [df1,df2,df3]
df = pd.DataFrame()
for d in dfs:
df = pd.merge(df, d, how = 'outer')