-2

I'm trying to merge two dataframes together but every time I try the merge I get the following message:

TypeError: merge() missing 1 required positional argument: 'right'

d = {'year': [2001, 2002], 'wsp': [0.51, 0.42]}
df = pd.DataFrame(data=d)
d2 = {'year': [2001, 2002], 'age': [50, 60]}
df2 = pd.DataFrame(data=d2)
join = pd.merge([df, df2], on='year')

The output I'm trying to get is: this

Any ideas? Thanks!

T Campbell
  • 47
  • 1
  • 8
  • Possible duplicate of [pandas merge two dataframes](https://stackoverflow.com/questions/46035432/pandas-merge-two-dataframes) – n1tk Dec 03 '17 at 06:00

3 Answers3

0

You have the basic idea down, just use one of the dataframes and the . method syntax to get the correct form:

join = df.merge(df2, on="year")

UberStuper
  • 356
  • 3
  • 17
0

You can also use the concat function

join = pandas.concat([df,df2]).drop_duplicates().reset_index(drop=True)

sat
  • 603
  • 3
  • 6
0

You don't need the parenthesis in the pd.merge.

d = {'year': [2001, 2002], 'wsp': [0.51, 0.42]}
df = pd.DataFrame(data=d)
d2 = {'year': [2001, 2002], 'age': [50, 60]}
df2 = pd.DataFrame(data=d2)
join = pd.merge(df, df2, on='year')

Output:

    wsp  year  age
0  0.51  2001   50
1  0.42  2002   60
Scott Boston
  • 147,308
  • 15
  • 139
  • 187