1

Let's say I have a dataframe (df) with two columns and a list of strings (my_string).

The objective is to find the longest match between each string in my_string to col_2 and insert the corresponding value of col_1 as an output. So, for instance, if:

my_string = ['289', '1', '12']

      col_1   col_2
df = [A       123
      B       230
      C       17]

I expect the output should be [B, [A,C], A]

Tried find_longest_match function from difflib but with no luck.

Any help would be appreciated.

0 Answers0