I have a dictionary dict
contains many (more than 100) dataframes. Each dataframe contains two variable name
and 'value_i'. For example, the first dataframe in this dictionary dict[1]
looks like the following:
name value_1
A 1
B 1.1
C 2
Similarly, the second dataframe in this dictionary dict2
looks like the following:
name value_2
A 1
B 1.1
D 1.3
I want to merge all dataframes within this dictionary by common variable name
.
The expected outcome should looks like the following:
name value_1 value_2
A 1 1
B 1.1 1.1
C 2 nan
D nan 1.3
I know I can do pd.merge[dict[i], dict[i-1], how = 'outer', on = 'name'
many times to merge all dataframes together. But this is too inefficient.
I tried pd.concat(dict.values(), axis = 1, join='outer'
But concat
dont allow me to merge by key variable.
Can anyone teach me how to do it more efficiently please?