0

I wanted to search a list of string on columns, and take a boolean output if the column contains the string, i have a list.

dl = df.astype(str).apply(lambda x: x.str.lower())

list = ['outlook', 'teamviewer']
match = len(list) 


for i in list:
   dl['Test'] = dl['User Agent'].str.contains(i , regex=False)

dl.head()

  • Does [this answer](https://stackoverflow.com/a/55335207/4909087) help? Check the "Multiple Substring Search" subheading. – cs95 Apr 07 '19 at 10:35

2 Answers2

0

Try:

dl['Test'] = dl['User Agent'].isin(['outlook', 'teamviewer'])

Edit:

df['Test'] = df['User Agent'].apply(lambda x: True if re.match('outlook|teamviewer', x) != None else False)

hacker315
  • 1,704
  • 1
  • 11
  • 18
0

Use Series.str.contains with values of list joined by | for regex OR,also added flags re.I for ignore case:

import re

L = ['outlook', 'teamviewer']
df['Test'] = df['User Agent'].str.contains('|'.join(L), flags=re.I)
jezrael
  • 629,482
  • 62
  • 918
  • 895
  • no, not work, getting all False, i am looking for partial match – MD SAQUIB NASIR KHAN Apr 07 '19 at 11:33
  • @MDSAQUIBNASIRKHAN - It is weird,because it should working. Is possible add some rows of sample data to question? I think [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) should help. – jezrael Apr 07 '19 at 11:36