我的数据集是这样的 然后我做了我的 tf_idf 矢量器 并得到了这个
但是当我想让它看起来像使用 pandas 的表格时,结果是 0
你们能帮我吗? :(
我尝试使用 toarray() 但结果全为零
一旦处理稀疏矩阵,请使用 pandas from_spmatrix。
这是一个例子:
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
corpus = ['This is the first document.','This document is the second document.','And this is the third one.','Is this the first document?']
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(corpus)
# Show the type of X
print(type(X))
# Convert to pandas dataframe
pd.DataFrame.sparse.from_spmatrix(X)