0

Is there a smart function which will "pivot" data frame containing strings?

A1 | B1 | C1
A2 | B1 | C2
A1 | B2 | C3
A1 | B3 | C4
A3 | B1 | C5
A2 | B2 | C6

Desired output:

___| B1 | B2 | B3
A1 | C1 | C3 | C4
A2 | C2 | C6
A3 | C5

nikefor
  • 1
  • 1
  • Did you try anything so far? and if you please provide more description to the desired output. – Ramy M. Mousa Nov 03 '17 at 01:16
  • Hi, thanks for your time. – nikefor Nov 03 '17 at 20:17
  • I'm trying to manipulate some data in the same way and there I have some problems. Unfortunately I didn't test data frame which I set as an example. And obviously it works. – nikefor Nov 03 '17 at 20:26
  • I was recieving: ValueError: Index contains duplicate entries, cannot reshape, and I have fixed it based on (https://stackoverflow.com/questions/28651079/pandas-unstack-problems-valueerror-index-contains-duplicate-entries-cannot-re) – nikefor Nov 03 '17 at 20:29

1 Answers1

1

You already mention pivot

df
Out[265]: 
    A   B   C
0  A1  B1  C1
1  A2  B1  C2
2  A1  B2  C3
3  A1  B3  C4
4  A3  B1  C5
5  A2  B2  C6

df.pivot('A','B','C')
Out[266]: 
B   B1    B2    B3
A                 
A1  C1    C3    C4
A2  C2    C6  None
A3  C5  None  None
BENY
  • 317,841
  • 20
  • 164
  • 234