我将需要删除字符串列表:
list_strings=['describe','include','any']
从熊猫的一栏:
My_Column
include details about your goal
describe expected and actual results
show some code anywhere
我试过了
df['My_Column']=df['My_Column'].str.replace('|'.join(list_strings), '')
但它会删除部分单词。
例如:
My_Column
details about your goal
expected and actual results
show some code where # here it should be anywhere
我的预期输出:
My_Column
details about your goal
expected and actual results
show some code anywhere
使用“单词边界”表达式\b
。
In [46]: df.My_Column.str.replace(r'\b{}\b'.format('|'.join(list_strings)), '')
Out[46]:
0 details about your goal
1 expected and actual results
2 show some code anywhere
Name: My_Column, dtype: object
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句