0

I'm trying to filter the contents of a dataframe. If a string is present in a column, those rows have to be stored in a new dataframe

    list1 = ['A+B','A']
    list2 = ['1','2']
    df = pd.DataFrame(
        {
         'name':list1,
         'value':list2
        }
    )
    temp_df = df[df.name.str.contains('A')]
    pprint(temp_df)

Output obtained:

      name value
    0  A+B     1
    1    A     2

Desired output:(only those that have an exact match)

  name value
0    A     2

Any suggestions on how this can be achieved?

Natasha
  • 1,111
  • 5
  • 28
  • 66

1 Answers1

2
temp_df[temp_df['name'] == 'A']
Behzad Mehrtash
  • 356
  • 2
  • 5