0

I am trying to compare two columns to see if strings in one column exist in another even if the row numbers don't match.

The columns look like this:

A              B   
Classic        Classic
Classic Rock   Rock
Kpop           Pop
Jpop           Hip-Hop
Rock           Classic Rock
Jazz           Jazz

I want to be able to create a new table with B that looks like the following:

B              C   
Classic        True
Rock           True
Pop            False
Hip-Hop        False
Classic Rock   True
Jazz           True

I tried using

df['C'] = df.apply(lambda x: x.A in x.B, axis=1)

But this only provided whether the strings in the row matched, and I'm looking for a way so that row placement does not matter.

user_seaweed
  • 141
  • 1
  • 8

0 Answers0