0

I have the following DataFrame df

value type
one 1
two 2
three 3

which I want to reshape such that the desired output would look like that

one two three
1 2 3

I used

df.pivot(columns="values", values="type")

which gave me this:

one two three
1 nan nan
nan 2 nan
nan nan 3

How can I get around the redundancies?

Michael
  • 189
  • 6

1 Answers1

0

You don't need to pivot the data, you can .Transpose it:

df.set_index('value').T

Out[22]: 
value  one  two  three
type     1    2      3
Andreas
  • 7,669
  • 3
  • 9
  • 30