0

Assuming df is this

    date        code    value
0   2007-04-02  0001    12
1   2007-04-02  0002    23
2   2007-04-02  0003    51
3   2007-04-02  0005    18
...

Would like to obtain the following, which is grouped by the date, but the code column will turn into the column names of the new df

    date        0001    0002    0003    0004
0   2007-04-02  12      23      51      18
1   2007-04-03  21      1       19      47
..
lrh09
  • 557
  • 4
  • 13

1 Answers1

1
df = df.set_index(['date', 'code']).squeeze().unstack().reset_index()
RichieV
  • 5,103
  • 2
  • 11
  • 24