如何在按列排序的同时对另一列进行排序

问题描述 投票:0回答:1

我正在尝试削减每个国家/地区的浮动值,同时按大陆对它们进行分组。 这是我写的代码:

groups = renew.groupby(['Continent'],pd.cut(renew['% Renewable'], 5))

我收到此错误

TypeError: can only concatenate str (not "float") to str

我不明白它试图在哪里连接,但我试图将“% Renewable”列中的值分成 5 个容器。

python cut bins
1个回答
0
投票

很难说为什么在没有看到数据的情况下会发生该特定错误,但首先将要分组的所有变量放在第一个参数中,例如

groups = renew.groupby(['Continent', pd.cut(renew['% Renewable'], 5)])
© www.soinside.com 2019 - 2024. All rights reserved.