pandas AttributeError:无法访问“DataFrameGroupBy”对象的可调用属性“groupby”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53406056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 06:10:07  来源:igfitidea点击:

AttributeError: Cannot access callable attribute 'groupby' of 'DataFrameGroupBy' objects

pythonpandasdataframepandas-groupby

提问by harry04

I have a dataframe that has 3 columns -

我有一个包含 3 列的数据框 -

enter image description here

在此处输入图片说明

I want to group the columns on the basis of Chopstick Length by doing something like this -

我想通过做这样的事情根据筷子长度对列进行分组 -

meansByCL = df_chopstick.groupby('Chopstick.Length')['Food.Pinching.Efficiency'].mean().reset_index()

but this throws an error -

但这会引发错误-

AttributeError: Cannot access callable attribute 'groupby' of 'DataFrameGroupBy' objects, try using the 'apply' method

I'm not sure what this error means. Can anyone tell me what I'm doing wrong or how I can write this code differently?

我不确定这个错误是什么意思。谁能告诉我我做错了什么或者我如何以不同的方式编写这段代码?

回答by harry04

This happens when you are trying to groupby()a dataframe which has been already grouped before!

当您尝试groupby()使用之前已经分组的数据框时会发生这种情况!