我有一个数据帧df
,其中包含未清理的文本字符串
phrase
0 the quick brown br fox
1 jack and jill went up the hill
我还有一个单词和字母分组的列表,我想remove
称为remove,如下所示:
['br', and]
在本例中,我希望得到以下输出:
phrase
0 the quick brown fox
1 jack jill went up the hill
请注意,“brown”中的br
不是作为一个较大单词的一部分保留在df
中,但是“br”本身被删除了
我试过:
df['phrase']=[re.sub(r"\b%remove\b", "", sent) for sent in df['phrase']]
但不能让它正常工作。有人能告诉我怎么做吗
谢谢
我觉得它可以随着
replace
下降对
split
使用嵌套列表理解,通过in
使用tes成员身份,并将拆分的值连接回:相关问题 更多 >
编程相关推荐