Compare dataframe column to another dataframe column

Viewed 331

I have a dataframe column containing page paths (let's call it A):

pagePath
/text/other_text/123-string1-4571/text.html
/text/other_text/string2/15-some_other_txet.html
/text/other_text/25189-string3/45112-text.html
/text/other_text/text/string4/5418874-some_other_txet.html
/text/other_text/string5/text/some_other_txet-4157/text.html
/text/other_text/123-text-4571/text.html
/text/other_text/125-text-471/text.html

And I have another string dataframe column let's call it (B) (the two dataframes are different and they don't have the same number of rows).

Here's an example of my column in dataframe B:

names
string1
string11
string4
string3
string2
string10
string5
string100

What I want to do is to check if my page paths (A) are containing strings from my other dataframe (B).

I had difficulties because my two dataframes haven't the same length and the data are unorganized.

EXPECTED OUTPUT

I want to have this output as a result:

 pagePath                                                  names     exist
/text/other_text/123-string1-4571/text.html                string1   TRUE
/text/other_text/string2/15-some_other_txet.html           string2   TRUE
/text/other_text/25189-string3/45112-text.html             string3   TRUE
/text/other_text/text/string4/5418874-some_other_txet.html string4   TRUE
/text/string5/text/some_other_txet-4157/text.html          string5   TRUE
/text/other_text/123-text-4571/text.html                     NA      FALSE
/text/other_text/125-text-471/text.html                      NA      FALSE

If my question needs more clarification, please mention this.

4 Answers
Related