Difference between pandas.merge and pandas.dataframe.merge?

What would be the reason to use one vs the other?

1 Like

Both are the same, you might be confused because of how it was written in the pandas documentation before and now.

Back in the 0.23.4 version it was pandas.merge as you can see here
Nowdays, in the 1.1.1 version it’s pandas.DataFrame.merge, here

But if you read both documentations the definition is the same

1 Like

Not the same in terms of how they’re called, same in terms of what they eventually do, both 0.23.4 and 1.1.1 had both api.

2 Likes

merge is a function in the pandas namespace, and it is also available as a DataFrame instance method merge() , with the calling DataFrame being implicitly considered the left object in the join.

As stated here

pd.DataFrame.merge is calling internally pd.merge function. pd.DataFrame.merge is wrapper function around pd.merge for easy use.

When we use pd.DataFrame.merge it will implicitly considered the left object in the join. So df1.merge(right=df2) is equivalent to pd.merge(left=df1, right=df2)

PS: pd.DataFrame.join also use pd.merge internally more detail in same reference

2 Likes

Thanks, the answers were very informative. Much appreciated! Essentially one function calls the other. @hanqi So awesome you’d written a whole article about a question I thought might go unanswered.