擅长:python、mysql、java
<p>对于任何不小的文本语料库,我强烈建议使用<code>scikit-learn</code>的<a href="https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html" rel="nofollow noreferrer">CountVectorizer</a>。在</p>
<p>简单到:</p>
<pre><code>from sklearn.feature_extraction.text import CountVectorizer
count_vectorizer = CountVectorizer()
word_counts = count_vectorizer.fit_transform(corpus) # list of documents (as strings)
</code></pre>
<p>它并没有为您提供所需结构中的dataframe,但是使用<code>count_vectorizer</code>的<code>vocabulary_</code>属性来构造它,该属性包含了该项到结果矩阵中其索引的映射。在</p>