0

I'm trying to convert my dataframe which is of the format:

file   config   value
name1  a        123
name1  b        123
name1  c        123
name2  a        456
name2  b        789
name2  c        123

As to have the following format:

file    a    b    c
name1   123  123  123  
name2   456  789  123

I want my 'config' values to become columns with the values equivalent to the 'value' column for each file.

Any hints on how I might achieve this?

Jurgen Palsma
  • 300
  • 1
  • 3
  • 16

2 Answers2

2

Thats pivot_table

df.pivot_table(index='file', columns='config', values='value')

config    a    b    c
file                 
name1   123  123  123
name2   456  789  123
rafaelc
  • 57,686
  • 15
  • 58
  • 82
1

Unstack it:

df.set_index(['file', 'config']).unstack()

       value          
config     a    b    c
file                  
name1    123  123  123
name2    456  789  123