I have calculated tf-idf matrices for 3 different columns in a.csv file and now want to store these values in one single csv file with column names as the column whose tf-idf values it is storing. I am new to python. Please help me with this problem.
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
import csv
data=pd.read_excel(r"C:\Users\amgup\Downloads\classification\Model_Dataset.xlsx", usecols=['Category','Title','Description'])
vectorizer = TfidfVectorizer()
matrix1 = vectorizer.fit_transform(data['Category'].values.astype(str))
matrix2 = vectorizer.fit_transform(data['Title'].values.astype(str))
matrix3 = vectorizer.fit_transform(data['Description'].values.astype(str))
Did you try to use np.savetxt
?
np.savetxt('data.csv', (matrix1 , matrix1 2, matrix3), delimiter=',')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.