I have a dataset of the following format:
msgText name
'My name is Donald' Donald
'I am married to Jenny' Donald
'Donald is from Europe' Donald
What I would like to do is replace parts of the msgText
column fs it contains the name from the name
column and I would like to replace it by 'Karl'. So that my desired output looks as follows:
msgText name
'My name is Karl' Donald
'I am married to Jenny' Donald
'Karl is from Europe' Donald
To do so, I have the following function:
def replaceName(text, name):
newText = text.replace(name, 'Karl')
return newText
However, I don't know how to apply this function to a Pandas series.
What I started with is:
dataset['filtered_text'] = dataset.msgText.apply(replaceName)
However, here I don't take the name coluimn into consideration. How can I use the apply function and use two columns as input variables to my function?