0

I am filtering a dataframe where a column == one of these numbers (must be in string format):

numbers = [
'013237918',
'70261045',
'70261125',
'70275745',
'70325295',
'70346445',
'70377495',
'70428835',
'74908083',
'75316203'
]

# filter the DF

df[df['column'].str.contains('|'.join(numbers))]

Which im 99% sure works.

However what if one of the rows contained my number, but also an extra number at the end. Or an extra letter. For example '70377495abx'. That would appear in the above search, however I don't want it.

I want the rows where the column equals exactly one of the items in the list.

Like

df[df['column'].str.equals('|'.join(numbers))]

Does something like this exist?

SCool
  • 3,104
  • 4
  • 21
  • 49
  • 2
    if you want _exact_ matches use `isin` the equivalent of `in` in SQL `df[column].isin(numbers)` – Umar.H Jul 14 '20 at 15:12

1 Answers1

0

Use

print(df[df['column'].isin(numbers)])
Balaji Ambresh
  • 4,977
  • 2
  • 5
  • 17