我有一个简单的Pandas数据框,我希望通过使用某个列对其进行分组。df看起来像下面的那个。你知道吗
Color Car
R Ford
O Kia
Y Mazda
R Chevrolet
我想按“颜色”分组,因此结果df将是:
Color Car
R Ford, Chevrolet
O Kia
Y Mazda
这似乎很容易使用熊猫群比。我的代码如下所示:
df = df.groupby(['Color'])
但我得到以下错误:
Cannot access callable attribute 'iloc' of 'DataFrameGroupBy' objects, try using the 'apply' method
为什么groupby不起作用?这似乎是最基本的操作,而groupby是最适合使用的?你知道吗
用途:
[输出]
相关问题 更多 >
编程相关推荐