0

Suppose I have the following contrived example:

    ids        types    values                                                                                                                                
     1          a         10                                                                                                                           
     1          b         11                                                                                                                             
     1          c         12
     2          a         -10
     2          b         -11 
     3          a         100

Is there way to use panda.pivot() to get the following table?

    ids      a     b     c                                                                                                                                 
     1       10    11    12   
     2      -10   -11    NaN 
     3       100   NaN   NaN                                                                                                                          

jshusko
  • 35
  • 4
  • 1
    duplicates of [how to pivot](https://stackoverflow.com/questions/47152691/how-to-pivot-a-dataframe): `df.pivot('ids','types', 'values')` – Quang Hoang May 08 '20 at 17:13

1 Answers1

1

You could try something like this -

df.pivot(index='ids', columns='types', values='values')
types      a     b     c
ids
1       10.0  11.0  12.0
2      -10.0 -11.0   NaN
3      100.0   NaN   NaN
Sajan
  • 1,247
  • 1
  • 5
  • 13