【发布时间】:2022-01-18 14:39:42
【问题描述】:
我正在尝试从文本数据段落中删除三个句子。我有一个 pandas 数据框,其中包含我想从中删除相同的三个句子的段落行。例如,
import pandas as pd
df_1 = pd.DataFrame({"text": ["the dog is red. He goes outside and runs.",
"i like dogs because they are fun. i don't like that dogs bark at mailmen",
"dogs bark at mailmen and i think its funny."]})
custom_stopwords = ["the dog is red", "i like dogs", "dogs bark at mailmen"]
for i in custom_stopwords:
df_1['text'] = df_1['text'].str.replace(i, '')
此方法在我提供的示例中有效,但不适用于我的实际数据。我拥有的数据非常大,但我不明白为什么在这种情况下这很重要。正在发生的事情是我的一些句子将被删除,而另一些则不会。例如,我无法删除单词“installation(s)”而不用“/”挡住括号。
【问题讨论】:
标签: python pandas text replace str-replace