Home > Back-end >  Python check if a dataframe single contains contains a keyword
Python check if a dataframe single contains contains a keyword

Time:09-29

  • I have a value in my df NEFT fm Principal Focused Multi.
  • I have a list of words containing keywords like NEFT, neft. So, if the above string of DF contains NEFT word, I want to add a new column and mark it as True.
  • Sample Input

enter image description here

  • I was trying
for index, row in ldf_first_page.iterrows():
    row.str.lower().isin(llst_transaction_keywords)
  • But it is trying to check the exact keyword, and I am looking for something like contains.

CodePudding user response:

Pardon me but I'm a beginner, have you perhaps tried using any()? I think this function matches what you need.

for index, row in ldf_first_page.iterrows(): row.str.lower().any(llst_transaction_keywords)

CodePudding user response:

Try:
for index, row in ldf_first_page.iterrows():
    if llst_transaction_keywords in row:
          return True
  • Related