【发布时间】:2021-08-18 13:59:11
【问题描述】:
我有一个包含对象列和超过 100,000 行的数据框,如下所示:
df['words']
0 the
1 to
2 of
3 a
4 with
5 as
6 job
7 mobil
8 market
9 think
10....
没有停用词的期望输出:
df['words']
0 way
1 http
2 internet
3 car
4 do
5 want
6 work
7 uber
8....
有没有办法使用 gensim、spacy 或 nltk 在单列中遍历常用的停用词?
我试过了:
from gensim.parsing.preprocessing import remove_stopwords
stopwords.words('english')
df['words'] = df['words'].apply(lambda x: gensim.parsing.preprocessing.remove_stopwords(" ".join(x)))
但这会导致:
TypeError: can only join an iterable
【问题讨论】:
-
x是什么类型? -
对象但更改为字符串。原始哥伦比亚对象类型。
-
你只能加入列表和迭代。您需要先转换为列表
-
我可以通过以下方式删除停用词:
stop_words = set(stopwords.words('english')) for word in new_words: if word not in stop_wordss: print(word)如何放回 df 中的新列? @mousetail
标签: python pandas nltk gensim stop-words