如何获得sklearnCountVectorizer
返回的术语频率矩阵中任何给定列的总和
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
corpus = [ 'This is a sentence',
'Another sentence is here',
'Wait for another sentence',
'The sentence is coming',
'The sentence has come'
]
x = vectorizer.fit_transform(corpus)
例如,我想找出矩阵中sentence
的频率。所以我想要sentence
列的和。我想不出一个办法:
x['sentence'].sum()
,但没有帮助
您可以尝试以下操作:
feature_names()
列表中的位置李>x
,在您的情况下)李>代码:
相关问题 更多 >
编程相关推荐