-1

I have a dataframe, df. One of the column is Text. I want to search the dataframe where the text contains ABC.

Hence, I write the code:

df["Text"].str.contains("ABC")

Now, I want to search which text contains ABC or XYZ.

What will be the syntax?

gremur
  • 1,645
  • 2
  • 7
  • 20
chocos
  • 1

2 Answers2

1

Using the | pipe is what you need

DF['Text'].str.contains('ABC|XYZ')
Rabinzel
  • 7,757
  • 3
  • 10
  • 30
  • 1
    I think you wanted `DF['Text'].str.contains('ABC|XYZ')` because `'ABC' | 'XYZ'` gives "TypeError: unsupported operand type(s) for |: 'str' and 'str'" – Henry Ecker Apr 16 '22 at 22:30
  • that's a very big yes. oops, thanks for pointing that out (didn't test that since I was at my phone) – Rabinzel Apr 16 '22 at 22:34
0
DF['Text'].str.contains('ABC') | DF['Text'].str.contains('XYZ')
Paul_0
  • 358
  • 4
  • 11