0

I have a data frame that looks like this:

speaker subject verb    tfidf
0   man i   learn   51.775912
1   man he  mean    51.195231
2   man she spend   48.590691
3 woman i   learn   47.025810
4 woman he  decide  46.472787

Two sets of speakers (men and women), each using three pronouns which are then paired with a variety of verbs, but the verbs overlap. I would like to reshape this data frame such that each verb is its own row and then there is a set of three columns for men and three columns for women. The three columns would be for the three pronouns -- he, she, i -- and their values would be the TFIDF scores.

SPEAKER       man               woman     
PRONOUN   i    he   she     i    he   she
VERB
learn    45     34    12    34   45     32
decide   ##     ##    ##   etc

I have looked at countless SO pages, Youtube videos, and scanned the pages of Effective Pandas to no avail. pandas has me beaten. Any advice here would be most appreciated.

John Laudun
  • 407
  • 1
  • 9
  • 19
  • For anyone coming here and seeing the disappointing fact that the question was closed within the hour and readers referred to previously not very helpful pages, there is in fact an answer that I discovered: `verbs = df.pivot_table(index='verb', columns=['speaker', 'subject'], values='tfidf', fill_value=0)`. Sadly, it was ChatGPT that provided the answer and not a live human being on SO who, as has been my experience, often take the time to provide an insight into why I couldn't see the bigger picture. It's the human touch that makes the difference. – John Laudun Aug 23 '23 at 13:45

0 Answers0