如何从数据框中删除单字单词,除了很少定义的单词(如* when what *)

时间:2019-01-16 05:31:37

标签: python-3.x pandas

如何从数据框中删除单义词,除了很少定义的词,例如何时

navigationItem

我想要输出

self.navigationItem

1 个答案:

答案 0 :(得分:0)

使用boolean indexing过滤由bitwise OR链接的多个带有掩码的单词,以过滤列表中定义的单词:

words = ['When','What']

df = df[(df['col'].str.split().str.len() != 1) | df['col'].isin(words)]
print (df)
               col
1  My name is khan
2             When
3             What
4        Opted bat

如果单词在列表中定义为小写:

words = ['when','what']
df = df[(df['col'].str.split().str.len() != 1) | df['col'].str.lower().isin(words)]