title: How to Transform sklearn tfidf vector pandas output to a meaningful format
body: <p>I have used sklearn to obtain tfidf scores for my corpus but the output is not in the format I wanted. </p>
  
  <p>Code:</p>
  
  <pre><code>vect = TfidfVectorizer(ngram_range=(1,3))
  tfidf_matrix = vect.fit_transform(df_doc_wholetext['csv_text'])
  
  df = pd.DataFrame(tfidf_matrix.toarray(),columns=vect.get_feature_names())
  
  df['filename'] = df.index
  </code></pre>
  
  <p><strong>What I have:</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/H6gsF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H6gsF.png" alt="enter image description here"></a></p>
  
  <p>word1, word2, word3 could be any words in the corpus. I mentioned them as word1 , word2, word3 for example.</p>
  
  <p><strong>What I need:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/weJkk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/weJkk.png" alt="enter image description here"></a></p>
  
  <p>I tried transforming it but it transforms all the columns to rows. Is there a way to achieve this ?</p>