0

In SQL when I expect the text on one column to contain the text of another, I could do something like:

select *
from a inner join b on a.col like '%' + b.col '%'

Is there a way to do that in Pandas? I've seen some posts like this https://stackoverflow.com/a/50573508/3515825 where they do a join and then filter. However, I only have one criteria/column to join on and I'm not sure where to start.

Should I start with a cross join merge and then filter? Is there a more efficient way to do that?

Update here is an example:

DF A
Name          Grade
Sam F. Jones  A
Rick Smith    B
DF B
Last Name   Year
Jones        12
Smith        10

I would like to join the two data frames based on the last name being in the name. Please note, that in reality, what I'm trying to is more complicated, I can't rely too much on the structure of the "Name" column.

Thank you!

VFR292
  • 89
  • 1
  • 7
  • kindly add a sample dataframe, with expected output. If you can, share code ``df.to_dict()`` – sammywemmy Jul 30 '21 at 00:23
  • see this [pandas-merging-101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – Anurag Dabas Jul 30 '21 at 04:29
  • 2
    I do not think what you want is possible. Pandas merge is much less powerful. – DYZ Jul 30 '21 at 04:37
  • 1
    @DYZ is right, Pandas does not have parsing ability and ease that SQL offers. you could also add an explanation for the SQL code for folks who are not familiar with SQL, along with the expected output. Or just write it in SQL and pull your data back into Pandas (if you really need it in Pandas) – sammywemmy Jul 30 '21 at 04:42

0 Answers0