Skip to content
Advertisement

Join pandas dataframes based on column values

I’m quite new to pandas dataframes, and I’m experiencing some troubles joining two tables.

The first df has just 3 columns:

DF1:

JavaScript

And the second has exactly same two columns (and plenty of others):

DF2:

JavaScript

What I need is to perform an operation which, in SQL, would look as follows:

JavaScript

And, as a result, I want to see DF2, complemented with column ‘position’:

JavaScript

What is a good way to do this using pandas?

Advertisement

Answer

I think you need merge with default inner join, but is necessary no duplicated combinations of values in both columns:

JavaScript

But if necessary position column in position 3:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement