2
我從R轉換到Python和具有樣品數據幀如下:str_replace_all()R等效在python
df = df = pd.DataFrame({'characterisitics': pd.Series(['Walter White made meth', 'Jessie Pinkman was called meth-head', 'Saul Goodman is always happy']), 'name': pd.Series(['Walter White', 'Jessie Pinkman', 'Saul Goodman'])})
characteristics name
0 Walter White made meth Walter White
1 Jessie Pinkman was called meth-head Jessie Pinkman
2 Saul Goodman is always happy Saul Goodman
我想用替代的匹配「名稱」列,找出「特徵」的部分每一行。在R,我可以用:
str_replace_all(string = df$characteristics, pattern = fixed(df$name), replacement = '')
而且我的輸出將如下所示:
characteristics name
0 made meth Walter White
1 was called meth-head Jessie Pinkman
2 is always happy Saul Goodman
我用什麼語法,如果我想在Python來實現這一目標?
謝謝!
感謝那些工作! –