0

I need to rotate the DF but it doesn't want to arrange itself the way I want it to. This is my DF:


wbp l    45
wbp ml   7
wbp k    27
wbp mk   37
bpz l    22
bpz ml   34
bpz k    12
bpz mk   41
pmh l    35
pmh ml   13
pmh k    9
pmh mk   44

I want to rotate DF like this:

      l    ml    k    mk
wbp  45    7     27   37 
bpz  22    34    12   41
pmh  35    13    9    44

How to do it?

maciej.o
  • 127
  • 1
  • 13

1 Answers1

1

Assuming your column names for those three columns are: A, B, C and your dataframe is called df

df.pivot(index='A', columns='B', values='C')
elevendollar
  • 1,115
  • 10
  • 19