1

Hi I have a input file similar to this

Order_id   ASIN         
1              abc1
1              abc3
2              cba2 
2              abc1 
2              bbc3 

What I am trying to create a metrics where ASIN will be column and Order_id will be row and for whichever ASIN falls under specific Oreder the value should be 1 else zero something similar like below.

              abc1         abc3    cba2      bbc3 
Order id 

  1             1           1       0          0            
  2             1           0       1          1

I tried following to do that using pandas.

  bskt = pd.pivot_table(df,index='Order_Id', columns='ASIN', 
          fill_value = 0)

But this is not returning the desire result. Please let me know what might I am doing wrong here.

Alternatively I added a new column quantity and keep the default value of 1 for all rows in it.
I tried below

  bskt = pd.pivot_table(df,index='Order_Id',values='Quantity', columns='ASIN', 
          fill_value = 0)

But this is also not giving the correct result.

J Doe
  • 112
  • 7
  • I saw that question earlier and use pivot but It gives me only 00 in all fields so I asked here – J Doe May 02 '18 at 11:12
  • @jezrael please answer this if possible I am not able to find the answer in given example – J Doe May 02 '18 at 11:24
  • Need `df = pd.pivot_table(df,index='Order_id', columns='ASIN', fill_value = 0, aggfunc='size')` – jezrael May 02 '18 at 11:26

0 Answers0