1

I have a table in pandas dataframe like below.

   Word      Term     Score
0   X          A        1
1   X          B        2
2   X          C        3
3   Y          A        4
4   Y          B        5
5   Y          C        6

I want to reshape it such that only the TERM column is transposed and values in Score column are shown under them like below:

Word   A  B  C
X      1  2  3
Y      4  5  6

I tried transpose and pivot but neither worked to fulfill my needs.

df.pivot(index='Word', columns='Term', values='Score')

pivot generated an error that the index contained duplicate entries and cannot reshape

raise ValueError('Index contains duplicate entries, ' ValueError: Index contains duplicate entries, cannot reshape

Cleb
  • 25,102
  • 20
  • 116
  • 151
  • 1
    Cannot reproduce. `df = pd.read_clipboard()` and `df.pivot(index="Word", columns="Term", values="Score")` work fine for me. – Cleb Jul 21 '19 at 19:34
  • 1
    I think i found the issue, there were duplicates with respect to the combination of columns Word and Term in the original table for some reason. I've excluded duplicates and it worked fine now. – Murali Krishna Pagolu Jul 21 '19 at 20:02

0 Answers0