sách gpt4 ai đã đi

python - 检查文本列 pandas 中停用词的数量

In lại 作者:行者123 更新时间:2023-11-28 20:56:00 26 4
mua khóa gpt4 Nike

如何检查文本列 pandas 中存在的停用词数量。我有一个庞大的数据集,非常感谢高效的方法。

from nltk.corpus import stopwords    
stop_words = set(stopwords.words('english'))

print(df)
chữ
0 stackoverflow is good
1 stackoverflow is not good

这是我想要的输出吗?

print(df)
text number_of_stopwords
0 stackoverflow is good 1
1 stackoverflow is not good 2

我试过类似下面的方法,但没有用。

df.str.split().apply(lambda x: len(x in stop_words))

1 Câu trả lời

使用集的交集:

from nltk.corpus import stopwords    
stop_words = set(stopwords.words('english'))

df['n'] = df['text'].str.split().apply(lambda x: len(set(x) & stop_words))

hoặc:

df['n'] = df['text'].apply(lambda x: len(set(x.split()) & stop_words))

print (df)
text n
0 stackoverflow is good 1
1 stackoverflow is not good 2

关于python - 检查文本列 pandas 中停用词的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55360559/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com