我为文本分析做了一个预处理部分,在删除停用词和词干后,如下所示:
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)