I have a dictionary of 10 Dataframes, and every Dataframe has 2 columns which are same in all 10 Dataframes, I would like to inner join all these datframes on these 2 columns and get a single dataframe
Asked
Active
Viewed 76 times
-4
-
Does this answer your question? [Pandas Merging 101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – Ignatius Reilly Jan 04 '23 at 18:11
1 Answers
1
You can use DataFrame.merge
with the functools.reduce
function. Assuming your DataFrames are the values of your dictionary called df_dict
:
from functools import reduce
df = reduce(lambda a, b: a.merge(b, on=['col1', 'col2']), df_dict.values())

jprebys
- 2,469
- 1
- 11
- 16