Python 乘法和groupby属性错误:无法访问可调用属性';mul&x27;属于';SeriesGroupBy';对象,请尝试使用';应用';方法

Python 乘法和groupby属性错误:无法访问可调用属性';mul&x27;属于';SeriesGroupBy';对象,请尝试使用';应用';方法,python,pandas,Python,Pandas,df 我想通过groupby对Person进行分组,并使用groupby找到Mul col的乘法 尝试: Person Mul col A 0 B 1 B 1 A 0 错误 AttributeError:无法访问“SeriesGroupBy”对象的可调用属性“mul”,请尝试使用“apply”方法改为使用prod: d

df

我想通过groupby对Person进行分组,并使用groupby找到Mul col的乘法

尝试:

Person           Mul col
 A                   0
 B                   1 
 B                   1
 A                   0 
错误


AttributeError:无法访问“SeriesGroupBy”对象的可调用属性“mul”,请尝试使用“apply”方法改为使用
prod

 df.groupby('Person')['Mul col'].mul()

改用
prod

 df.groupby('Person')['Mul col'].mul()
基本语法:

df.groupby('Person', as_index=False)['Mulcol'].prod()

     Person  Mulcol
0      A       0
1      B       1
根据您的代码:

>>>df.groupby([col_name]).prod()
基本语法:

df.groupby('Person', as_index=False)['Mulcol'].prod()

     Person  Mulcol
0      A       0
1      B       1
根据您的代码:

>>>df.groupby([col_name]).prod()

嗨@shailaja,别忘了你可以投票并接受答案。看,谢谢!当然可以。事实上,堆栈溢出不允许我在不等待10分钟的情况下接受答案,因此无法向上投票,后来我就退出了。嗨@shailaja,别忘了你可以向上投票并接受答案。看,谢谢!当然可以。实际上,堆栈溢出不允许我在不等待10分钟的情况下接受答案,因此无法进行投票,后来我就退出了。