-4

I have a CSV file with columns such as:

df =
title body
A     yellow, gree
B     blue, red
C     red, green
D     grey, blue

I would like to create a new dataframe with those rows that contain the word red:

df_New =
title body
B     blue, red
C     red, green

My code so far looks like this:

import pandas

Documents = pandas.read_csv(df.csv)

words = ['red', 'Red']

Df_New = Documents.str.match('(words)')
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Economist_Ayahuasca
  • 1,648
  • 24
  • 33

1 Answers1

0

You can use .str.contains()

df_ = df[df['body'].str.contains('red', case=False)]
print(df_)

  title        body
1     B   blue, red
2     C  red, green
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52