I'm trying to find the first occurance of a pattern in a string for each string in a pandas column. Here's what I have so far:
drilling_df['rig_number'] =
drilling_df['contractor_name'].apply(search_contractor_name)
def search_contractor_name(name):
test = re.search(
r'(?!^)(?<!\bNo\.\s)(?<!\bDivision of\s)(?<!\d)(?!(?:19[6-9][0-9]|20[01][0-9]|2020)(?!\d))(\d+(?!\d)e?)',
name)
if test:
return test.group()
else:
return ""
I ran this code but I keep getting this error:
TypeError: expected string or bytes-like object
I can't seem to figure out what I'm doing wrong. Thanks in advance for any help.