I have a dataframe and I want to replace a string by another string. I am using this code:
df['text']=df['text'].map(lambda x: x.replace('%%user_article%%','a'))
df['text']=df['text'].map(lambda x: x.replace('%%company_name%%','COMPANY'))
and it's working just fine.
Now I want to define a function with the code above and I did:
def r_tag(df):
df=df.map(lambda x: x.replace('%%user_article%%','a') \
.replace('%%company_name%%','COMPANY'))
return df
and then r_tag(df['text']
The function above works but don't persist the replacements. How can I fix this?