0

I am trying to write code that will look through a list of column names and determine if any of the column names match any entries I have in a list of strings and regexes. In the list of regexes, I have " r'\bday\b' " which is not matching a column name equal to "day"

The code I have written is essentially :

import re

df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
                   columns=['day', 'APPLES', 'Friday'])
datestrings = ['date', 'date_completed', r'\bday\b', r'\bmonth\b'] 

for i in df.columns:
    if any(x in str(i).lower() for x in datestrings):
        print('success')

I need the if check to pass whenever the variable i is equal to 'day', but not when it's equal to 'friday'. With the code I have written above, it fails in both cases.

0 Answers0