I have a pandas dataframe df with ids as strings: I am trying to create the new_claim and new_description columns
Closest SO I found was Efficiently replace part of value from one column with value from another column in pandas using regex? but this uses split part, and since the description changes I was unable to generalize.
I can run a one off
date_reg = re.compile(r'\b'+df['old_id'][1]+r'\b')
df['new_claim'] = df['claim'].replace(to_replace=date_reg, value=df['external_id'], inplace=False)
But if I have
date_reg = re.compile(r'\b'+df['claim']+r'\b')
Then I get "TypeError: 'Series' objects are mutable, thus they cannot be hashed"
Another approach I took
df['new_claim'] = df['claim']
for i in range(5):
old_id = df['old_id'][i]
new_id = df['external_id'][i]
df['new_claim'][i] = df['claim'][i].replace(to_replace=old_id,value=new_id)
which givesa TypeError: replace() takes no keyword arguments