0

I am trying to merge about 5 Data Frames, each with 2 variables. Each data frame has two variables. The variables are Unique_ID and Year. Each data frame has a different amount of observations.

DF 1

Unique ID        Year
1                2010
2                2010
3                2011

DF 2

Unique ID        Year
3                2010
2                2011
4                2012

What is the best way to merge them? I don't mind duplicates. I am actually trying to see how many I have.

David Erickson
  • 16,433
  • 2
  • 19
  • 35
  • What would be your expected output, just from merging the two dataframes you have posted above? You can add an arbitrary third column that can better showcase this. – David Erickson Oct 14 '20 at 03:28

2 Answers2

0

You can use functools.partial:

import functools
dfs = [df1,df2,df3,df4,df5]
df = functools.partial(pd.merge, on=['Unique_ID', 'Year']) #may have to pass how='outer' or how='left', depending on what you are trying to accomplish
David Erickson
  • 16,433
  • 2
  • 19
  • 35
0

you can use pandas.concat:

merged = pandas.concat([df1,df2,df3,df4,df5])

This will add up all your dataframes

Josh C
  • 1
  • 1