0

I want to transpose only the status and count column

From

Week    Status   Count
2021-01  High    186
2021-01 Medium   21
2021-01 Low      632
2021-02 High     144
2021-02 Medium    2
2021-02 Low      20
2021-02 Very_High 648

to

 Week   High Medium Low Very_High
 2021-01 186  21    632    0
 2021-02 144  2     20   648   
JackJack
  • 153
  • 7

1 Answers1

0

Use pivot:

out = df.pivot('Week', 'Status', 'Count').reset_index().rename_axis(index=None, columns=None)
print(out)

# Output
      Week   High    Low  Medium  Very_High
0  2021-01  186.0  632.0    21.0        NaN
1  2021-02  144.0   20.0     2.0      648.0
Corralien
  • 109,409
  • 8
  • 28
  • 52