我想使用.replace函数来替换多个字符串.
我现在有
string.replace("condition1", "")
Run Code Online (Sandbox Code Playgroud)
但是想要有类似的东西
string.replace("condition1", "").replace("condition2", "text")
Run Code Online (Sandbox Code Playgroud)
虽然那感觉不是很好的语法
这样做的正确方法是什么?有点像grep/regex你可以做什么\1,\2并将字段替换为某些搜索字符串
全部,
要替换某一列中的一个字符串,我已经完成了此操作,并且效果很好:
dataUS['sec_type'].str.strip().str.replace("LOCAL","CORP")
Run Code Online (Sandbox Code Playgroud)
我现在想用一个字符串替换多个字符串说替换["LOCAL", "FOREIGN", "HELLO"]为"CORP"
怎样才能让它发挥作用?下面的代码不起作用
dataUS['sec_type'].str.strip().str.replace(["LOCAL", "FOREIGN", "HELLO"], "CORP")
Run Code Online (Sandbox Code Playgroud)