I need to write a strict regular expression to replace certain values in my pandas dataframe. This is an issue that was raised after solving the question that I posted here.
The issue is that the .replace(idsToReplace, regex=True) is not strict. Therefore if the iDsToReplace are:
NY : New York
NYC : New York City
and the comment in which we are replacing the ID is:
My cat from NYC is large.
The resulting response is:
My cat from New York is large.
Is there a pythonic way within the pandas replace function to make the regular expression stricter to match with NYC and not NY?