我如何在python中从大数据集(csv文件)的单个列上运行TF-IDF?

问题描述 投票:0回答:1

我正在尝试创建一个运行大数据集的TF-IDF的python程序。它具有多列和几行数据。我的问题是我不知道如何限制它仅在标题为“评论”的列之一上运行。

python tf-idf
1个回答
0
投票

您可以取出必填列的值并在其上运行TF-IDF:

from sklearn.feature_extraction.text import TfidfVectorizer

doc=df['Comments'].values #df is your dataframe
tf = TfidfVectorizer(stop_words='english')
tfidf_matrix = tf.fit_transform(doc)

希望有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.