Skip to content
Advertisement

Create Pandas DataFrame from 2 tuple lists with common first elements

I currently have 2 lists of tuples, both of which have the same information on the first element of the tuple. I’m trying to see if there is a way to “Join” these two tuple lists in a dataframe based on their common elements. Something like an SQL JOIN on a common column.

Lists are something like this:

JavaScript

and what I’m trying to achieve is a dataframe that looks something like this:

JavaScript

Ideally, I dont want to “extract” the first element of a single list into a separete one and use that as the first column. I really want this “Join on the common column” functionality. The reason being that Im not sure that the tuples match on every single place and so I would like that be cared for automatically (like in SQL).

Advertisement

Answer

Try this,

Code:

JavaScript

Output:

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