Created
January 1, 2020 04:26
-
-
Save jkmackie/b65f75796a731520841b76fe8fbdd0cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def match_regex_patt(df, target_col, regex_patt, no_match_value='None'): | |
'''Returns regex_patt matches as list. Case is ignored.''' | |
matchList=[] | |
cnt = 0 | |
for idx in df.index: | |
m = re.search(regex_patt, df.loc[idx, target_col], flags=re.IGNORECASE) #re.search(pattern, string) gets first match | |
if m is not None: | |
matchList.append(m.group(1).lower()) | |
else: | |
cnt+=1 | |
matchList.append(no_match_value) | |
print(f'In {target_col}, {cnt} missed matches for regex pattern: {regex_patt}.') | |
return matchList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment