1

initial code

num1  num2  num3  
0  A     a     1.1
1  A     b     1.3
2  A     c     .8
3  B     a     .4
4  B     b     1.2
5  B     c     2.1

I want it to be

   a    b    c
A  1.1  1.3  .8
B  .4   1.2  2.1

I tried df.set_index('num1') and df.set_index('num2').T but they didn't seem to get what I wanted.

calc_coder
  • 11
  • 2

1 Answers1

0

Use that:

your_table = pd.pivot_table(df, values='num3', index=['num1'],
                    columns=['num2'], fill_value=0)
Lukas Kaspras
  • 409
  • 1
  • 5
  • 15