数据df:
input:df.pivot('类别','产地','数量')
output:ValueError: Index contains duplicate entries, cannot reshape
查了官方文档发现原因是:两个columns不能有行重复
>>> df foo bar baz 0 one A 1 1 one A 2 2 two B 3 3 two C 4 Notice that the first two rows are the same for our `index` and `columns` arguments. >>> df.pivot(index='foo', columns='bar', values='baz') Traceback (most recent call last): ... ValueError: Index contains duplicate entries, cannot reshape
但是excel是可以计算的如下,当然不能去重也excelpivot的缺点:
在python,pivot_table可以实现
不指定aggfunc,默认为均值