0

I'd like to convert the following DataFrame:

   idx  key  val
0    1  foo    2
1    1  bar    4
2    1  qux    8
3    2  foo   10
4    2  bar   12
5    2  qux   14

To:

     key_foo  key_bar  key_qux
idx                           
1          4        2        8
2         12       10       14

That is: each key becomes a colummn key_<key>, with the idx column becoming the new index by which the key-value pairs are grouped into rows.

How should I do that? The DataFrame is very large, so I'd like to perform that transformation efficiently.

Goh
  • 167
  • 5

0 Answers0