【发布时间】:2021-09-14 17:34:36
【问题描述】:
我有一个带有一些三元组(以及更多 ngram)的 df,我想检查句子是否以特定单词列表开头或结尾,并将它们从我的 df 中删除。例如:
import pandas as pd
df = pd.DataFrame({'Trigrams+': ['because of tuna', 'to your family', 'pay to you', 'give you in','happy birthday to you'], 'Count': [10,9,8,7,5]})
list_remove = ['of','in','to', 'a']
print(df)
Trigrams+ Count
0 because of tuna 10
1 to your family 9
2 pay to you 8
3 give you in 7
4 happy birthday to you 5
我尝试使用strip,但在上面的示例中,第一行会返回因为 tun
输出应该是这样的:
list_remove = ['of','in','to', 'a']
Trigrams+ Count
0 because of tuna 10
1 pay to you 8
2 happy birthday to you 5
有人可以帮我吗?提前致谢!
【问题讨论】:
标签: python pandas string data-cleaning trim