I'm having two dataframes in pandas, the one is initial one:
and the other is the result of TF-IDF operation. So basically, Name was grouped by Group and then sklearn TF-IDF was applied like that:
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
frame = df.groupby(['Group'])['Name'].apply(' '.join).reset_index()
vect = TfidfVectorizer()
tfidf = vect.fit_transform(frame)
yy=pd.DataFrame(tfidf.toarray(), columns=vect.get_feature_names())
yy['Group']=frame['Group']
Right now I would like to join two dataframes (which, for sure, I can do using merge() using Group as ID) but I would like also to use column names from the second dataframe to join with respective values in Name column in first dataframe to construct something like that:
How can this be achieved in pandas and do I need to use for loops for completing this?


