-1

I would like to perform the following:

for each row, check if the df['Text'] matching any string in every row in df1['Criteria'], matching even one of them will result in true.

Thanks!

import pandas as pd
import numpy as np
df = pd.read_csv('Test excel.csv')
df1 = pd.read_csv('Sorting Critiria.csv')
df['Match'] = df['Text'].str.contains(df1['Criteria 1'])

#seems like only 'actual' string can be put inside str.contains()

1 Answers1

0

Use join by | for regex or:

df['Match'] = df['Text'].str.contains('|'.join(df1['Criteria 1']))
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252