I have two DataFrames, one containing a column with lists inside its cells. Here is an example:
DF 1 :
| A B
---+----------------------------
0 | 'A' ['A', 'B']
1 | 'B' ['B', 'D']
2 | 'C' ['D', 'E', 'F']
DF 2 :
| C D
---+----------------------------
0 | 'A' 'X'
1 | 'B' 'Y'
2 | 'C' 'Z'
Here is the code to setup the DataFrames :
df1 = pd.DataFrame({'A': ["A", "B", "C"], "B": [["A", "B"], ["B", "D"], ["D", "E", "F"]]})
df2 = pd.DataFrame({'C': ["A", "B", "C"], "D": ["X", "Y", "Z"]})
I would like do an inner join between DF1 and DF2 with the condition DF2.C in DF1.B
, here is the result I expect:
DF1&DF2 :
| A B C D
---+--------------------------------------
0 | 'A' ['A', 'B'] 'A' 'X'
1 | 'A' ['A', 'B'] 'B' 'Y'
2 | 'B' ['B', 'D'] 'B' 'Y'
I read the documentation explaining how to achieve a join using concat
, but I cannot find how to use membership testing as a join condition.
Did I missed something? Any idea on how to do it?