MADBOWLofSOUP
MADBOWLofSOUP

Reputation: 45

Receiving a TypeError when using the merge() method with Pandas

I'm trying to merge two data frames on a column with a int data type

df3 = df2.merge('df1', how = 'inner', on = 'ID')

But I receive this error

TypeError: Can only merge Series or DataFrame objects, a (class 'str') was passed

I do not understand what is causing this, so any help would be appreciated!

Upvotes: 2

Views: 5517

Answers (2)

Everton
Everton

Reputation: 11

You need to pass the variable 'df1' reference directly, not as a string:

df3 = df2.merge(df1, how = 'inner', on = 'ID')

Alternatively you can pass both dataframes as a parameter:

df3 = pd.merge(df1, df2, how = 'inner', on = 'ID')

Upvotes: 1

jmdatasci
jmdatasci

Reputation: 111

The way you have written is calling to merge df2 with 'df1' as a computer this looks like trying to merge a dataframe with the literal phrase 'df1', try removing the quotations and do just df1 as an object.

Upvotes: 1

Related Questions