My first dataframe contains sentences I tokenized, the second is a matrix of all the TFIDF of each word in each sentence.
I'm trying to create a new column where only the TFIDF of the words in the sentence are stored. How can i do it ?
Tokenize sentences table
| Index | Tokenized_string |
|---|---|
| 1 | [word1,word2,word3] |
| 2 | [word1,word3,word4] |
Tfidf Table
| Index | Word1 | Word2 | ... |
|---|---|---|---|
| 1 | 0.03 | 0.06 | ... |
| 2 | 0.5 | 0.5 | ... |
The table I'm trying to create
| Index | Tokenized_string | TFIDF of each word |
|---|---|---|
| 1 | [word1,word2,word3] | [0.03,0.06,0.1] |
| 2 | [word1,word3,word4] | [0.5,0.4,0.2] |
To create the dataframes in my exemple:
import pandas as pd
df = pd.DataFrame({ 'Tokenized_string':
[['word1','word2','word3'],
['word1','word3','word4']]
})
df_2 = pd.DataFrame({ 'Tokenized_string':
[['word1','word2','word3'],
['word1','word3','word4']],
'TFIDF of each word':
[[0.03,0.06,0.1],
[0.5,0.4,0.2]]})