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

har*_*y04 5 python dataframe pandas pandas-groupby

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

在此处输入图片说明

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

meansByCL = df_chopstick.groupby('Chopstick.Length')['Food.Pinching.Efficiency'].mean().reset_index()
Run Code Online (Sandbox Code Playgroud)

但这会引发错误-

AttributeError: Cannot access callable attribute 'groupby' of 'DataFrameGroupBy' objects, try using the 'apply' method
Run Code Online (Sandbox Code Playgroud)

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

har*_*y04 7

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