-2

I have a dataframe like this:

   Description     keyword
1  plays the piano   plays
2  plays the piano   write
3  plays the piano   piano
4 knows how to write  the
5 knows how to write  to

I want to filter it so that I keep the rows where the keyword is in the description. So here I would like to keep:

   Description     keyword
1  plays the piano   plays
3  plays the piano   piano
5 knows how to write  to

Is there an efficient way to do this?

1 Answers1

1

Assuming your dataframe is called df:

df[df.apply(lambda x: x['keyword'] in x['Description'], axis=1)]
Jan Z
  • 171
  • 3