1

Here's my the dataset

OUTLET CODE  WEEK
000052         31
000052         27
000052         39
000035         29
000035         31
000035         38
000038         38
000038         29
000038         31

Here's what I try

df.groupby(['OUTLET_CODE', 'WEEK']).count()

Here's the output

OUTLET_CODE   WEEK
000035         29
               31
               38
000038         29
               31
               38
000052         27
               29
               31
               39

Here's type of output that I want

                                 WEEK
OUTLET_CODE            27 29 31 38 39
000035                  0  1  1  1  0
000038                  0  1  1  1  0
000052                  1  1  1  0  1

How suppose I do this?

Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70

1 Answers1

4
df = pd.pivot_table(df, values='WEEK', index='OUTLET_CODE', columns='WEEK', aggfunc=len, fill_value=0)
naivepredictor
  • 898
  • 4
  • 14