Skip to content
Advertisement

Python Pandas non equal join

Have table

OUT

Need:

so i need make non equal join equivalent SQL query :

or as SQL query:

The problem in PANDAS is that NON EQUAL SELF JOIN cannot be done with MERGE. And I can’t find another way…..

Advertisement

Answer

We can solve this in pandas in a smarter way by using groupby with agg and joining the strings. Then we split them to columns:

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