小编Yur*_*let的帖子

将 CountVectorizer 应用于 Python 中行中单词列表的列

我为文本分析做了一个预处理部分,在删除停用词和词干后,如下所示:

test[col] = test[col].apply(
    lambda x: [ps.stem(item) for item in re.findall(r"[\w']+", x) if ps.stem(item) not in stop_words])

train[col] = train[col].apply(
    lambda x: [ps.stem(item) for item in re.findall(r"[\w']+", x) if ps.stem(item) not in stop_words])
Run Code Online (Sandbox Code Playgroud)

我有一个列有“清理词”列表的列。这是一列中的 3 行:

['size']
['pcs', 'new', 'x', 'kraft', 'bubble', 'mailers', 'lined', 'bubble', 'wrap', 'protection', 'self', 'sealing', 'peelandseal', 'adhesive', 'keeps', 'contents', 'secure', 'tamper', 'proof', 'durable', 'lightweight', 'kraft', 'material', 'helps', 'save', 'postage', 'approved', 'ups', 'fedex', 'usps']
['brand', 'new', 'coach', 'bag', 'bought', 'rm', 'coach', 'outlet']
Run Code Online (Sandbox Code Playgroud)

我现在想将 CountVectorizer 应用于此列

from …
Run Code Online (Sandbox Code Playgroud)

python cpu-word bag sparse-matrix countvectorizer

7
推荐指数
2
解决办法
7573
查看次数

标签 统计

bag ×1

countvectorizer ×1

cpu-word ×1

python ×1

sparse-matrix ×1