我有下面的一段代码,它将“Tokens”中的所有单词与“df”中的每个文档进行比较。有什么方法可以让我将预定义的单词列表与文档(而不是“标记”)进行比较。在
from sklearn.feature_extraction.text import TfidfVectorizer
tfidf_vectorizer = TfidfVectorizer(norm=None)
list_contents =[]
for index, row in df.iterrows():
list_contents.append(' '.join(row.Tokens))
# list_contents = df.Content.values
tfidf_matrix = tfidf_vectorizer.fit_transform(list_contents)
df_tfidf = pd.DataFrame(tfidf_matrix.toarray(),columns= [tfidf_vectorizer.get_feature_names()])
df_tfidf.head(10)
感谢任何帮助。谢谢您!在
不确定我是否理解您的意思,但是如果您想让向量器考虑一个固定的单词列表,您可以使用
vocabulary
参数。在相关问题 更多 >
编程相关推荐