I have some text stored in pandas.Series. for example:
df.loc[496]
'therapist and friend died in ~2006 Parental/Caregiver obligations:\n'
I need to replace the number in the text with full date, so I wrote
df.str.replace(
pat=r'(?:[^/])(\d{4}\b)',
repl= lambda m: ''.join('Jan/1/', m.groups()[0]),
regex=True
)
but the output is nan; though I tried to test the regular expression using findall, and there is no issue:
df.str.findall(r'(?:[^/])(\d{4}\b)')
496 [2006]
I don't understand what the issue is. most of the problems raised are about cases where Series type is number and not str; but my case is different the data type obviously is str. Nonetheless, I tried .astype(str)
and still have the same result nan.
A possible solution:
Output: