TypeError:pivot_table()为关键字参数“值"获得了多个值 [英] TypeError: pivot_table() got multiple values for keyword argument 'values'

查看:859
本文介绍了TypeError:pivot_table()为关键字参数“值"获得了多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python2.7.我正在学习熊猫,并且正在实现pivot_table.在实现ivot_table 文档 中给出的示例时:

I am using Python2.7. I am learning pandas and was implementing pivot_table. While implementing the example given in pivot_table documentation :

    raw_data = {'A':['foo','foo','foo','foo','foo','bar','bar','bar','bar'],
        'B':['one','one','one','two','two','one','one','two','two'],
        'C':['small','large','large','small','small','large','small','small','large'],
        'D':[1,2,2,3,3,4,5,6,7]}
    df = pd.DataFrame(raw_data)
    df.pivot_table(df,index = ['A','B'], values = 'D',columns = 'C', aggfunc = 'sum')

运行时,出现以下错误: TypeError:pivot_table()为关键字参数值"获得了多个值

When run, I get the following error : TypeError: pivot_table() got multiple values for keyword argument 'values'

任何人都可以知道为什么会这样吗?

Can anyone tell why this is happening ?

推荐答案

您需要删除df:

              #here      
df.pivot_table(df,index = ['A','B'], values = 'D',columns = 'C', aggfunc = 'sum')


a = df.pivot_table(index = ['A','B'], values = 'D',columns = 'C', aggfunc = 'sum')
print (a)
C        large  small
A   B                
bar one    4.0    5.0
    two    7.0    6.0
foo one    4.0    1.0
    two    NaN    6.0

这篇关于TypeError:pivot_table()为关键字参数“值"获得了多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆