I have multiple dataframes df1, df2, df3,...
that i want to merge based on the index. All of these have some columns that are duplicates in other dataframes.
For example:
In[1]: df1
Out[2]:
col1 col2
1697352 Other Dynamic
1698918 Other Other
1698957 Static Dynamic
1698645 Static Static
In[3]: df2
Out[4]:
col1 col2
1697352 Other Force
1698918 Other Power
1698957 Static Force
1698645 Static Power
In[5]: df3
Out[6]:
col1 col2 col3
1697352 Left Force Other
1698918 Right Power Other
1698957 Middle Force Static
1698645 Left Power Static
...
I would want something like this:
In[7]: df_merged
Out[8]:
col1 col2 col3 col4
1697352 Other Dynamic Force Left
1698918 Other Other Power Right
1698957 Static Dynamic Force Middle
1698645 Static Static Power Left
...
With two dataframes I have used,
cols_merged = df1.columns.differences(df2.columns)
and then merge them with
pd.merge(df1, df2[cols_merged], left_index=True, right_index=True)
Is there a way of doing this in on go?