python pandas pivot_table count frequency in one column

You need to specify the aggfunc as len:

In [11]: df.pivot_table(index='Account_number', columns="Product", 
                        aggfunc=len, fill_value=0)
Out[11]:
Product         A  B
Account_number
1               2  0
2               1  2
3               1  1

It looks like count, is counting the instances of each column (Account_number and Product), it’s not clear to me whether this is a bug…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)