I want to filter through my column headers and pull out columns that match specific strings. Currently I do this using lines in my code that go like this:
word_possibilities = ['word1', 'word2', 'word3']
new_df = (df.filter(regex='|'.join(re.escape(x) for x in word_possibilities)).columns.to_list())
This works fine, except it pull out columns with headers like 'word111' for example. I would like it to select only columns that match the word possibilities exactly, not just contain the string.
Is there a way to modify the line for this?