0

i have some dataset df and i need check rows only with special values of strings in name column

so i need make df[df.name.str.contains('John', regex=True)]

this will outputs me df with John names

i can make logic OR like df[df.name.str.contains('John|James', regex=True)]

this will make me outputs df with John or James names

but how i can make contains with two values at the same time? for example we have name like James John Williams, and i need return only this row (string need contains John AND James)?

germanjke
  • 529
  • 1
  • 5
  • 13

1 Answers1

0

How about :

df_out = df[df.name.str.contains('John', regex=True) & df.name.str.contains('James', regex=True)]

works both ways e.g John James / James John

el_bobo
  • 101
  • 4