Используйте split
всеми связанными значениями |
для regex OR
и выберите сначала list
s на str[0]
:
remove_words = ['stack', 'over', 'flow']
#for more general solution with word boundary
pat = r'\b{}\b'.format('|'.join(remove_words))
df['col'] = df['col'].str.split(pat, n=1).str[0]
print (df)
col
0 abc test test
1 cde test12
2 def123
3 yup
Вы можете заключить строку в обратные метки литерала шаблона и передать ее в eval
для запуска интерполяции строки:
saveQuery = eval('`' + saveQuery.saveQuery + '`');
const a = 10;
const str = 'test ${a} test';
console.log(eval('`' + str + '`'));
/*
if it's required to wrap the interpolated value into a quotes,
you can do that by wrapping the embedded expression, prior to interpolation:
*/
console.log(eval('`' + str.replace(/(\${.*})/, '\'$1\'') + '`'));